I have a Button control inside a DataTemplate for my ListBoxItem with a TextBlock inside it:
<DataTemplate x:Key="SomeitemTempate"> .... <Button x:Name="nxBut" Margin="20,0,20,20" Height="30" DockPanel.Dock="Bottom" FontSize="16" Background="White" Click="nxBut_Click"> <TextBlock x:Name="nxBut_Txt" Text="Some Button" FontWeight="Bold" Foreground="#FF11700C"/> </Button> .... Now when user clicked the Button, I want to change IsEnabled property of the button to False, and the Text of the TextBlock to "Clicked". After googling for some times, i modified it:
.... <DataTemplate.Triggers> <DataTrigger Binding="{Binding ElementName=nxBut, Path=IsPressed}" Value="True"> <Setter TargetName="nxBut" Property="IsEnabled" Value="False" /> <Setter TargetName="nxBut_Txt" Property="Text" Value="Clicked"/> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> But it does not work. What am I doing wrong?
<ToggleButton IsEnabled="{Binding IsChecked, RelativeSource={RelativeSource Self}, Converter="{StaticResource InvertedBoolConverter"}}"/>So once it's clicked, that's it, it's disabled, until it is somehow reset be it manually or if a screen re-renders or something. Not sure of your requirements but you could save the bool if it needs to stay persistent. Your Inverted bool converter on it will just make it so IF IsChecked=True, THEN IsEnabled=FalseConverterstuff. I wrote "if ((bool)value == true) { return false; } return true;" When i click the button an error occured :(