0

いくつかの列を持つデータグリッドがあります。オブジェクトのリストにバインドされます。列の1つはテキスト列です。「検証」列として必要です。実際、各行について、このセルの値は、他のセルに存在する値に基づいて「OK」または「NOT OK」である必要があります. Datagrid の特定のセルに文字列を書き込む方法がわかりません。なにか提案を?

編集: DataGrid のオブジェクトを記述するクラスに従う

public class BracketProperty
{
    [XmlAttribute]
    public int index { get; set; }
    public BracketType type { get; set;}
    public List<BracketPoint> bracketPointsList;
    [XmlIgnore]
    public String isPointSelectionEnded { get; set; }
}

EDIT2:このコード行は良くないと誰かが言っています

this.BracketsDataGrid.ItemsSource = this.currentPropertyToShow.sides[this.sideIndex - 1].brackets;

は次のようにbrackets定義されます

 public ObservableCollection<BracketProperty> brackets;

はバインディングではないため...どうすればバインディングに変更できますか?

4

3 に答える 3

0

値コンバーターを使用する

public partial class MainWindow : Window
{
    public ObservableCollection<Employee> EmpList { get; set; }
    public MainWindow()
    {

        InitializeComponent();
        this.DataContext = this;
        EmpList = new ObservableCollection<Employee> { 
            new Employee(1, "a"), 
            new Employee(2, "b"), 
            new Employee(3, "c") };
    }
}

public class NumValueConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        int v = int.Parse(value.ToString());
        if (v < 3) 
            return "YES";
        else 
            return "NO";
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

public class Employee
{
    public int Salary { get; set; }
    public string Name { get; set; }

    public Employee(int s, string n)
    {
        Salary = s;
        Name = n;
    }
}

XAML

<Window x:Class="garbagestack.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cv="clr-namespace:garbagestack"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Resources>
            <cv:NumValueConverter x:Key="cv1"/>
        </Grid.Resources>
        <DataGrid AutoGenerateColumns="False" Margin="12,99,12,12" Name="dg1" ItemsSource="{Binding EmpList}" >
            <DataGrid.Columns>
                <DataGridTextColumn Header="NewValue" Binding="{Binding Salary}"/>
                <DataGridTextColumn Header="NewValue" Binding="{Binding Name}"/>
                <DataGridTextColumn Header="NewValue" Binding="{Binding Salary,Converter={StaticResource cv1}}">

                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
于 2013-10-07T16:04:50.133 に答える