I have a window which has a tabcontrol. Content of one of the tab items is set to a usercontrol. There is a button in my main window whose IsEnabled property needs to be set to a property that is exposed by the usercontrol. I hope to do this the clean way ie using binding.
If that is not possible, then I can do it the dirty way by setting the button's IsEnabled property in the usercontrol. I tried some solutions posted on this group to get access to the main window, but I am not able to get it.
Any help with either of the approaches is greatly appreciated.
This can be done by giving the usercontrol a name, here is an example with a checkbox but it stands with usercontrols as well.
<Window x:Class="WpfApplication5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TabControl>
<TabItem Header="Tab1">
<CheckBox Name="checkBox1">Toggle to toggle button isEnabled</CheckBox>
</TabItem>
</TabControl>
<Button Grid.Row="1" IsEnabled="{Binding IsChecked, ElementName=checkBox1}"></Button>
</Grid>
</Window>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.