vladc77
vladc77

Reputation: 1064

How to bind IsChecked property of radio that exists in different user control?

I am looking for the ways to bind IsChecked property of a radio button that exist in one user control to a button that exists in another user control. Both user controls are loaded into MainWindow. Any ideas are highly appreciated.

Code for MainWindow:

<Grid x:Name="LayoutRoot">
    <Frame Content="Frame" Source="/WpfApplication1;component/Page1.xaml"/>
    <local:NavUserControl HorizontalAlignment="Center" VerticalAlignment="Bottom"/>
</Grid>

Code Page1:

<Grid x:Name="LayoutRoot">
    <local:ContentUC HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

Code For user Control 1:

<Grid x:Name="LayoutRoot">
    <RadioButton x:Name="RadioBt1" Content="Enable Next Button" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

Code For user Control 2:

<StackPanel x:Name="LayoutRoot" Orientation="Horizontal" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="0,0,0,20">
    <Button Content="Back" HorizontalAlignment="Left" Width="75"/>
    <Button Content="Next" HorizontalAlignment="Left" Width="75" IsEnabled="{Binding IsChecked, ElementName=RadioBt}" />
</StackPanel>

Upvotes: 2

Views: 221

Answers (1)

Jeff Yates
Jeff Yates

Reputation: 62377

Following the principles of encapsulation, you need the parent UserControl of the RadioButton to expose that button's IsChecked property as its own. This then enables your button that sits outside of the UserControl to bind to that property.

For that to occur, you will need to modify the code-behind for the UserControl to add the appropriate property (IsNextEnabled for example) and DependencyProperty (e.g. IsNextEnabledProperty) that will then map to the RadioButton's property.

Upvotes: 2

Related Questions