开发者

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

I am look开发者_运维知识库ing 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜