0

BackgroundFontWeight、をForegroundに変更したいと思いdxg:GridColumnます。このコードを書きましたが、残念ながら動作しません。どうすれば修正できますか?

public class CellViewModel {
    public string Value { get; set; }
    public string FontWeight { get; set; }
    public string Foreground { get; set; }
    public string Background { get; set; }
}

public class TestItemViewModel {
    public CellViewModel Column1 { get; set; }
    public CellViewModel Column2 { get; set; }
    public CellViewModel Column3 { get; set; }
}

public class TestViewModel {
    public TestViewModel() {
        this.Items = new ObservableCollection<TestItemViewModel> {
            new TestItemViewModel {
                Column1 = new CellViewModel { Value = "CCC", FontWeight = "Bold", Foreground = "Red", Background = "Green" }, 
                Column2 = new CellViewModel { Value = "-683,84", FontWeight = "Normal", Foreground = "Red", Background = "SeaGreen" }, 
                Column3 = new CellViewModel { Value = "-683,84", FontWeight = "Normal", Foreground = "Red", Background = "SeaGreen" }, 
            }
        };
    }
    public ObservableCollection<TestItemViewModel> Items { get; set; }
}

<dxg:GridControl HorizontalContentAlignment="Right"
                 AutoPopulateColumns="False"
                 ItemsSource="{Binding Path=Performance.Items}">
    <dxg:GridControl.Resources>
        <DataTemplate x:Key="GridColumnHorizontalContentAlignmentTemplate">
            <dxe:TextEdit x:Name="PART_Editor" HorizontalContentAlignment="Right" />
        </DataTemplate>
    </dxg:GridControl.Resources>
    <dxg:GridControl.Columns>
        <dxg:GridColumn AllowColumnFiltering="False"
                        CellTemplate="{StaticResource GridColumnHorizontalContentAlignmentTemplate}"
                        FieldName="BuyAndHold.Value"
                        Header="Column 1"
                        HorizontalHeaderContentAlignment="Right">
            <dxg:GridColumn.CellStyle>
                <Style TargetType="dxg:CellContentPresenter">
                    <Setter Property="Background" Value="{Binding Path=Column1.Background}" />
                    <Setter Property="FontWeight" Value="{Binding Path=Column1.FontWeight}" />
                    <Setter Property="Foreground" Value="{Binding Path=Column1.Foreground}" />
                </Style>
            </dxg:GridColumn.CellStyle>
        </dxg:GridColumn>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
         <dxg:TableView AllowEditing="False"
                        AllowGrouping="False"
                        AllowSorting="False"
                        NavigationStyle="None"
                        PrintTotalSummary="False"
                        ShowGroupPanel="False"
                        ShowHorizontalLines="False"
                        ShowIndicator="False"
                        ShowTotalSummary="False"
                        ShowVerticalLines="False" />
    </dxg:GridControl.View>
</dxg:GridControl>

なぜあるのか理解できない

<Style TargetType="dxg:CellContentPresenter">
    <Setter Property="Background" Value="{Binding Path=BuyAndHold.Background}" />
    <Setter Property="FontWeight" Value="{Binding Path=BuyAndHold.FontWeight}" />
    <Setter Property="Foreground" Value="{Binding Path=BuyAndHold.Foreground}" />
</Style>

データバインディングはありませんか?

値を手動で設定すると、すべてが機能します。例えば。

<Setter Property="Background" Value="Red" />

正常に動作します。

4

1 に答える 1

0

使用しているバインディングのパスが間違っています。
次の構文を使用します。

<Setter Property="Background" Value="{Binding Path=RowData.Row.BuyAndHold.Background}"/>

それ以外の:

<Setter Property="Background" Value="{Binding Path=BuyAndHold.Background}"/>

関連例:スタイルを条件付きで適用する方法(CellStyle)

于 2012-08-23T05:13:11.490 に答える