zoukankan      html  css  js  c++  java
  • 可以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>
  • 相关阅读:
    一个貌似比较吊的递归转换为loop--总算成功了.
    为何反转迭代顺序就不会栈溢出了?
    将树形递归转换为loop
    递归和迭代之间的转换简单例子
    非线性递归函数转化为迭代函数举例
    将尾递归函数转换为迭代函数的利器
    转:LINUX/UNIX下的回车换行与WINDOWS下的区别
    property干嘛的
    eval和列表解析的一处陷阱
    剑指offer——16二进制中1的个数
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3305071.html
Copyright © 2011-2022 走看看