I have a UserControl within a frame on it's parent window. In the usercontrol, I have a textbox that needs to be edited when a button on the parent window is toggled.
I'm trying to do it using triggers UserControl.xaml
<UserControl.Resources>
<ResourceDictionary>
<Style x:Key="TextBoxEdit" TargetType="TextBox">
<Setter Property="IsReadOnly" Value="True" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=EditButton}" Value="True">
<Setter Property="IsReadOnly" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<TextBox
x:Name="EditTextBox"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Style="{StaticResource TextBoxEdit}"
Text="Edit me" />
</Grid>
This works fine when there is a button named EditButton within the usercontrol, but is it possible to do this when the EditButton is within the parent window?
MainWindow.xaml
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<ToggleButton x:Name="EditButton" HorizontalAlignment="Center" VerticalAlignment="Top">Edit</ToggleButton>
<Frame Grid.Row="1" Source="Home.xaml" />
</Grid>
It is my understanding that the data context for the usercontrol will be inherited from the parent window, so is it possible to do it as simple as a trigger bound to the button or will I have to use a viewmodel/button commands?