usercontrol与class'的绑定属性会员

时间:2017-07-13 12:11:24

标签: c# universal

制作Windows 8:Universal Application,我有以下问题:

为什么在Height方法中将新值分配给MyGridView.Items后,height中每个控件的MyGridView_SelectionChanged都不会更改?在OnNavigatedTo方法中,它正确设置Height值...

public sealed partial class NewPage : Page
{
    public double height;


    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        foreach (var card in e.Parameter as List<MyClass>)
        {
            MyControl myControl = new MyControl(card);
            BindingOperations.SetBinding(myControl, HeightProperty, new Binding { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay, Source = this, Path = new PropertyPath("height") });
            MyGridView.Items.Add(myControl);
        }
    }

    private void MyGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        height = 100;
    }
}

我也试过了DependencyProperty

public static readonly DependencyProperty MyGridViewItemHeightProperty = DependencyProperty.Register("MyGridViewItemHeight", typeof(double), typeof(GridViewItem), null);

public double MyGridViewItemHeight
{
    set { SetValue(MyGridViewItemHeightProperty, value); }
    get { return (double)GetValue(MyGridViewItemHeightProperty); }
}


protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    foreach (var card in e.Parameter as List<MyClass>)
    {
        MyControl myControl = new MyControl(card);
        BindingOperations.SetBinding(myControl, HeightProperty, new Binding { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, Mode = BindingMode.TwoWay, Source = this, Path = new PropertyPath("MyGridViewItemHeightProperty") });

    }
}

但它给出了相同的结果......

0 个答案:

没有答案