![](/img/trans.png)
[英]Hide specific context menu in datagrid upon selected row wpf mvvm
[英]Selected Row on WPF Datagrid LostFocus mvvm Pattern
我有這個問題:
我有一個包含以下內容的用戶控件:1)一個DataGrid
<DataGrid x:Name="GrdHistoricalInformation"
Style="{StaticResource BaseDataGridStyle}"
SelectedIndex="0"
ItemsSource="{Binding BarList}"
HorizontalScrollBarVisibility="Auto"
BorderThickness="1"
BorderBrush="Black"
HorizontalAlignment="Stretch"
CanUserSortColumns="False"
DockPanel.Dock="Top"
ColumnHeaderHeight="50"
SelectedItem="{Binding SelectedBar, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
2)一個帶有某些單選按鈕的用戶控件,這些單選按鈕具有在我的視圖模型上觸發的命令。
我的問題是,當我選擇一行然后按下單選按鈕時,網格上的所選項目會丟失“突出顯示”(即使我在視圖模型中正確綁定了所選項目)
在這里我選擇一行:
然后當我按RB失去焦點時
而且由於mvvm模式,我無法在解決方案上使用事件。
任何建議或幫助將不勝感激! 提前致謝。
編輯:
嘗試過這種風格:
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="Selector.IsSelectionActive" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="#660066"/>
</MultiTrigger>
</Style.Triggers>
但仍然無法正常工作。
嘗試以下方法:
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#660066" />
<Setter Property="BorderBrush" Value="#660066" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
DataGridRow具有2種視覺狀態:Normal_Selected和Unfocused_Selected。 您的樣式似乎在Unfocused_Selected中未定義任何顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.