xamlにこのコードがあります。このコードは、マウスの上にマウスを置いてマウスをクリックすると色付けされます。プロパティ値をプログラムで変更した後、WPF XAMLデータトリガーが起動しないC#
<Border x:Class="DatasetGrid.RowHeaderButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" MinWidth="30" Width="Auto">
<Border.Resources>
<SolidColorBrush x:Key="ButtOverBrush" Color="#53C3D5" Opacity="0.2"></SolidColorBrush>
<SolidColorBrush x:Key="ButtPressedBrush" Color="#53C3D5" Opacity="0.5"></SolidColorBrush>
</Border.Resources>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="Transparent"></Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource ButtOverBrush}"></Setter>
</Trigger>
<DataTrigger Binding="{Binding IsMouseDown, RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="Background" Value="{StaticResource ButtPressedBrush}"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
これはすべてが順調と良い作品が、私はすぐに私が背後にあるコードで背景色を変更すると、上記のマウスオーバーとMouseDownイベントのトリガーはもう発生しませんがわかります。
RowHeaderButton rhb = RowHeadersColumn.VisibleRowHeaders[cell.CellInfo.RowIndex];
rhb.Background = new SolidColorBrush(Color.FromArgb(100, 83, 195, 213));
私はので、私は間違って何が起こっているのかわからないんだけど、WPFにはかなり新しいです。
編集:
そこでグリッドに行ヘッダすなわち、上記の私の制御がRowHeaderButtonあり、いくつかのより多くの情報を与えます。グリッド内の各行には、独自の行ヘッダボタンがあります。したがって、ユーザーが上に移動したりクリックしたりすると、上から指定されたSolidColorBrushに変更されます。
別のコントロールDataGrid.xaml.csのコードビハインドには、グリッドの同じ行のセルが選択されたときに行ヘッダーの色が変更される以下のコード(簡略化されたコード)があります。 。
void UpdateSelectedCells() {
foreach (Cell cell in VisibleColumns.SelectMany(c => c.VisibleCells))
{
int cellRowIndex = cell.CellInfo.RowIndex;
cell.IsSelected = SelectedCells.Contains(cell.CellInfo);
foreach (RowHeaderButton rhb in RowHeadersColumn.VisibleRowHeaders)
{
int rowHeaderIndex = Convert.ToInt16(rhb._default.Text) - 1;
if (cellRowIndex == rowHeaderIndex)
{
if (cell.IsSelected)
{
rhb.Background = new SolidColorBrush(Color.FromArgb(100, 83, 195, 213));
}
else
{
bool rowselected = false;
//need to check if any other cell in the row is selected, if not then color row header white
foreach (CellInfo celll in SelectedCells)
{
if (celll.RowIndex == cellRowIndex)
{
rowselected = true;
break;
}
}
if (rowselected == false)
rhb.Background = Brushes.White;
}
}
}
}
}
私はこのためのViewModelを持っていません。
シンプルなViewModelを作成すると、GUI要素を直接変更することなく、コードをより簡単にGUIに変更できますが、バインドされたプロパティは変更されます。 – Tony