wpf datepicker可见性绑定不起作用

时间:2018-01-09 18:20:25

标签: wpf binding datepicker visibility

我想在xaml中编码所有元素,但是通过代码隐藏显示和隐藏某些方依赖于步骤。 在这里,我修改了代码以使其无法使用,因此我将两种适当的方法都放弃了 问题是关于itemscontrol和datepicker的可见性,因为第二个从不从代码隐藏中获取值

拥有此代码:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <DockPanel Grid.Row="0" Name="d1">
        <ItemsControl Name="Panel" ItemsSource="{Binding Content}" Visibility="{Binding Panel_Visibility}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>

            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Height="100" Width="100" Margin="5" Content="{Binding Content}" Command="{Binding Button_Click}" CommandParameter="{Binding Content}"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DockPanel>
    <StackPanel Grid.Row="1" Name="d2">
        <DatePicker Name="DateVoyage" Visibility="{Binding DateVoyage_Visibility}"/>

    </StackPanel>

</Grid>

并且:

class Page_Modele : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    ...

    private Visibility panel_visibility;
    public Visibility Panel_Visibility {
        get { return this.panel_visibility; }
        set {
            this.panel_visibility = value;
            OnPropertyChanged("Panel_Visibility");
        }
    }

    private Visibility datevoyage_visibility;
    public Visibility DateVoyage_Visibility {
        get { return this.datevoyage_visibility; }
        set {
            this.datevoyage_visibility = value;
            OnPropertyChanged("DateVoyage_Visibility");
        }
    }

    ...

    public Page_Modele()
    {
        this._data = new donnees();
        Panel_Visibility = Visibility.Collapsed;
        DateVoyage_Visibility = Visibility.Collapsed;
        this.Content = itemsourc.Get_itemsourc(Execute1_ButtonClick, this._data.getContinentsList());

    }
    ...
}

ItemsControl已折叠,但DatePicker未折叠。 我错过了什么?

0 个答案:

没有答案