グリッド列のスタイルを設定していますが、カスタム テンプレートの列とデフォルト テンプレートの列があります。
ビューを初めてロードしたとき、スタイルはデフォルト テンプレートの列に適用されませんが、(実行時に) グリッド内の列を追加/削除すると、すべての列にスタイルが適用されていることがわかります。
私のコードビハインドは、次の添付プロパティを定義します
public static readonly DependencyProperty GridLinesBorderBrushProperty = DependencyProperty.RegisterAttached("GridLinesBorderBrush", typeof(SolidColorBrush), typeof(CarbonBlotter), new PropertyMetadata(Brushes.Transparent));
public static readonly DependencyProperty GridLinesBorderThicknessProperty = DependencyProperty.RegisterAttached("GridLinesBorderThickness", typeof(Thickness), typeof(CarbonBlotter), new PropertyMetadata(new Thickness(0)));
public SolidColorBrush GetGridLinesBorderBrush(UIElement element_)
{
return (SolidColorBrush)element_.GetValue(GridLinesBorderBrushProperty);
}
public void SetGridLinesBorderBrush(UIElement element_, SolidColorBrush value_)
{
element_.SetValue(GridLinesBorderBrushProperty, value_);
}
public Thickness GetGridLinesBorderThickness(UIElement element_)
{
return (Thickness)element_.GetValue(GridLinesBorderThicknessProperty);
}
private void ShowGridLines()
{
UserSettings.GridLineType gridLineType = _userSettings.ShowGridLines;
Thickness gridLinesBorderThickness = new Thickness(0, 0, 1, 1);
if (gridLineType == UserSettings.GridLineType.Off)
{
SetGridLinesBorderThickness(_grid, new Thickness(0));
SetGridLinesBorderBrush(_grid, Brushes.Transparent);
SetAllowGridLines(_grid, false);
}
else (gridLineType == UserSettings.GridLineType.Black)
{
SetGridLinesBorderThickness(_grid, gridLinesBorderThickness);
SetGridLinesBorderBrush(_grid, Brushes.Black);
SetAllowGridLines(_grid, true);
}
}
そして私のXamlにはデフォルトのテンプレートがあります
<Style TargetType="ig:CellValuePresenter" BasedOn="{StaticResource {x:Type ig:CellValuePresenter}}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderThickness" Value="{Binding Path=DataPresenter.(pwc:CarbonBlotter.GridLinesBorderThickness), RelativeSource={RelativeSource Self}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ig:CellValuePresenter}">
<igw:CardPanel>
<Border x:Name="MainBorder" CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Padding="4"/>
...
そして、デフォルトのテンプレートに基づくカスタムテンプレートがいくつかあります
<Style x:Key="_columnStyle" TargetType="{x:Type ig:CellValuePresenter}" BasedOn="{StaticResource {x:Type ig:CellValuePresenter}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border BorderBrush="{TemplateBinding BorderBrush}" Margin="{TemplateBinding Margin}" BorderThickness="{TemplateBinding BorderThickness}">
<pwc:BlotterCashTradingLanguageBar/>
</Border>
...
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
また、列名に応じて、デフォルトまたはカスタム テンプレートが適用されます。ビューを初めて起動すると、デフォルトのテンプレートの列には境界線がありませんが、列をいくつか追加してビューを変更すると、ビューが更新され、すべての列にグリッド線が表示されます。
ビューが初めて読み込まれるときに、既定のテンプレートが添付プロパティから値を選択していないようです。
何か案は。