制作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") });
}
}
但它给出了相同的结果......