Hi, I have customized the datacard styling, including an info button in the header. When the info button is clicked, I would like to show more information about the specific datacard. The problem now is that the datacard needs to be selected first. I would like it to be selected before the button's click is handled.
I would like the same behavior for the expand/collapse button, so when it is clicked the datacard is also selected.
The Button is within the ControlTemplate of the CardHeaderPresenter:
<Button x:Name="BtnInfo" Style="{StaticResource BtnInfoImageSq}" Command="{Binding DataContext.DcShowOrderDetails, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Width="20" Height="20" HorizontalAlignment="Right" Grid.Column="2" Margin="5"> </Button>
It tried to bind the IsActive and IsSelected Properties within the CardViewCard style to its IsKeyboardFocusWithin property like so:
<DataTrigger Binding="{Binding Path=IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}}" Value="True"> <Setter Property="IsSelected" Value="True"/> <Setter Property="IsActive" Value="True"/> <Setter TargetName="Bd" Property="BorderBrush" Value="Pink"/> <!-- test, this works, datatrigger is firing --> </DataTrigger>
The IsSelected and IsActive properties are not changing with the IsKeyBoardFocusWithin property, while the borderbrush does. It seems to me that the DataTrigger doesn't 'know' where the properties belong to, but I can't find out how to fix this.
Anyone who can show me the right way to solve this with the currently provided info?
Hello Paul,
Thank you for your post!
I have been looking into it and what I can suggest is to get the CardViewCard inside the Click event of the Button. You can do this by adding the following code snippet in the event handler or in the command you are using for the Click event of the Button:
CardViewCard clickedCard = ((sender as Button).TemplatedParent as CardHeaderPresenter).Card;
This way you can get the card itself and set it's IsSelected and IsActive properties.
Please do not hesitate to let me know if you have any further questions on this matter.
Hi Gergana,
Thanks for your suggesting. Your example within an event works perfectly, although I rather stay away from the code behind (mvvm). I am new to commands so I have to look in to them how to get the sender pass through as an parameter.
Thanks again
Thank you for the feedback. I am glad I was able to help. Regarding how to pass the sender as parameter you can take a look at the following link: http://www.codeproject.com/Tips/665546/Passing-Command-Parameter-for-Buttons-within-an .