• wpf DataGridComboBoxColumn


    <Window x:Class="WpfApplication5.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApplication5"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"
    Title="MainWindow" Name="this" Height="556" Width="851">

    <StackPanel>

            <DataGrid ItemsSource="{Binding Path=SelectedList,ElementName=this}" AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="文本模式" Binding="{Binding Path=Value}" />
                    <DataGridComboBoxColumn Header="ComboBox模式" SelectedValueBinding="{Binding Path=Value}" ItemsSource="{Binding Path=SelectionList,ElementName=this}" />
                    <DataGridTemplateColumn Header="Template模式">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox SelectedValue="{Binding Path=Value}" ItemsSource="{Binding Path=SelectionList ,ElementName=this}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridComboBoxColumn Header="ComboBox模式(修正)">
                        <DataGridComboBoxColumn.EditingElementStyle>
                            <Style TargetType="ComboBox">
                                <Setter Property="ItemsSource" Value="{Binding Path=SelectionList,ElementName=this}" />
                                <Setter Property="SelectedValue" Value="{Binding Path=Value,UpdateSourceTrigger=PropertyChanged}"/>
                            </Style>
                        </DataGridComboBoxColumn.EditingElementStyle>
                        <DataGridComboBoxColumn.ElementStyle>
                            <Style TargetType="ComboBox">
                                <Setter Property="ItemsSource" Value="{Binding Path=SelectionList,ElementName=this}" />
                                <Setter Property="SelectedValue" Value="{Binding Path=Value}"/>
                            </Style>
                        </DataGridComboBoxColumn.ElementStyle>
                    </DataGridComboBoxColumn>
                </DataGrid.Columns>
            </DataGrid>
            <Button Content="观察选中的数据" Click="Button_Click" Margin="10"/>
            <TextBox Name="TBX_Selected" />
        </StackPanel>
    </Window>
    public class DataItem
        {
            public int Value { get; set; }
            public DataItem(int val) { Value = val; }
        }
    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                SelectedList.Add(new DataItem(1));
                SelectedList.Add(new DataItem(2));
                SelectedList.Add(new DataItem(3));
                SelectedList.Add(new DataItem(3));
                SelectedList.Add(new DataItem(3));
                SelectedList.Add(new DataItem(3));
                SelectedList.Add(new DataItem(3));
                // 可选数据
                SelectionList.Add(1);
                SelectionList.Add(2);
                SelectionList.Add(3);
            }
            public ObservableCollection<int> SelectionList
            {
                get { return _selectionList; }
                set { _selectionList = value; }
            }
            private ObservableCollection<int> _selectionList = new ObservableCollection<int>();
            public ObservableCollection<DataItem> SelectedList
            {
                get { return _selectedList; }
                set { _selectedList = value; }
            }
            private ObservableCollection<DataItem> _selectedList = new ObservableCollection<DataItem>();
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                TBX_Selected.Text = "";
                foreach (var item in SelectedList)
                    TBX_Selected.Text += item.Value.ToString(" --->0<--- ");
            }
        }
  • 相关阅读:
    Windows下IntelliJ IDEA中调试Spark Standalone
    Java中final修饰符深入研究
    Java对象创建过程补遗
    SpringMVC项目中获取所有URL到Controller Method的映射
    简述Java中Http/Https请求监听方法
    WPF浏览器应用程序与JS的互调用(不用WebBrowser)
    通讯协议序列化解读(一) Protobuf详解教程
    Protobuf3语法详解
    ReflectASM-invoke,高效率java反射机制原理
    FFMPEG指令
  • 原文地址:https://www.cnblogs.com/xinzheng/p/5370869.html
Copyright © 2020-2023  润新知