• 可以binidng属性的属性【项目】


    1:binding后台bool[]数据以及后台ObservableCollection数据

    分别见下面xaml的VisibilityText的Binding

    public bool[] RubberTypeLegends
            {
                get
                {
                    bool[] result = new bool[] {false,false,false };
                    for (int i = 0; i < ResultItems.Count; i++)
                    {
                        result[i] = true;
                    }
                    return result;
                }
            }
    ...
    <StackPanel x:Name="OSL_Legend"
                            Margin="30,0,0,0"
                            Orientation="Horizontal"
                            Visibility="{Binding RubberTypeLegends[1],
                                                 Converter={StaticResource boolToVisibilityConverter}}">
                    <Rectangle Width="10"
                               Height="10"
                               Fill="Blue" />
                    <TextBlock Margin="5,0,0,0"
                               FontSize="9pt"
                               Style="{StaticResource Univers57_Condensed}"
                               Text="{Binding ResultItems[1].RubberType}" />
                </StackPanel>
    ...
    private ObservableCollection<OilSwellResultsItemViewModel> _resultItems;
    
            public ObservableCollection<OilSwellResultsItemViewModel> ResultItems
            {
                get
                {
                    if (_resultItems == null)
                        _resultItems = new ObservableCollection<OilSwellResultsItemViewModel>();
                    return _resultItems;
                }
    
                set
                {
                    if (_resultItems != value)
                    {
                        _resultItems = value;
                        this.RaisePropertyChanged("ResultItems");
                    }
                }
            }
    public class OilSwellResultsItemViewModel : NotificationObject
    {
    ...
    private string _rubberType;
    
            public string RubberType
            {
                get { return _rubberType; }
                set
                {
                    if (_rubberType != value)
                    {
                        _rubberType = value;
                        this.RaisePropertyChanged("RubberType");
                    }
                }
            }
    ...
    }

    2:binding wpf control自己的属性

    注意Binding="{Binding Items.Count, ElementName=DataGrid}"的ElementName是指向DataGrid

    <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding Items.Count, ElementName=DataGrid}" Value="1">
                    <Setter TargetName="OS_Legend" Property="Visibility" Value="Visible" />
                    <Setter TargetName="OSL_Legend" Property="Visibility" Value="Collapsed" />
                    <Setter TargetName="OSLSR_Legend" Property="Visibility" Value="Collapsed" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Items.Count, ElementName=DataGrid}" Value="2">
                    <Setter TargetName="OS_Legend" Property="Visibility" Value="Visible" />
                    <Setter TargetName="OSL_Legend" Property="Visibility" Value="Visible" />
                    <Setter TargetName="OSLSR_Legend" Property="Visibility" Value="Collapsed" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Items.Count, ElementName=DataGrid}" Value="3">
                    <Setter TargetName="OS_Legend" Property="Visibility" Value="Visible" />
                    <Setter TargetName="OSL_Legend" Property="Visibility" Value="Visible" />
                    <Setter TargetName="OSLSR_Legend" Property="Visibility" Value="Visible" />
                </DataTrigger>
            </ControlTemplate.Triggers>
  • 相关阅读:
    获取当前时间的时间戳
    js获取时间戳
    排序(一)冒泡,选择,插入
    MATLAB入门(一)数组
    锐捷客户端下虚拟机VMware无法联网的问题
    C++ Primer 读书笔记
    LA 4329 树状数组入门
    BZOJ 4352 预处理 + DP
    BZOJ 1954 (POJ 3764) Trie的经典应用 求树上最大异或值
    BZOJ 1597 斜率优化
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3305071.html
Copyright © 2020-2023  润新知