我需要列是动态的并且值 来改变我点击按钮的时间。
我创建了一个方法,当激活该方法时,它会将值传递给一个变量,该变量将通过绑定用于关联。
private void clickedColumnDefinition()
{
ColumnDefinition1 = 420;
}
此方法的属性具有声明的GrindLenght:
private GridLength _columnDefinition1;
public GridLength ColumnDefinition1 {
get { return _columnDefinition1; }
set { SetProperty(ref _columnDefinition1, value); }
}
在xaml中,像这样定义列:
<ColumnDefinition Width="{Binding ColumnDefinition1, Converter={StaticResource numberToGridLengthConverter}}"/>
我使用的转换器是这一个,但当我按下按钮时什么也没发生.
public class NumberToGridLengthConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var numberValue = (double)value;
return new GridLength(numberValue, GridUnitType.Star);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var gridLength = (GridLength)value;
return gridLength.Value;
}
}
会有什么问题呢?
1条答案
按热度按时间lyfkaqu11#
如果您想将
RowDefinition
的高度设置为动态值,您可以执行以下操作:1.创建视图模型
RowHeightClass
2.绑定
MainPage.xaml
中的属性,如下所示:3.MainPage.xaml.cs
我为这个视图模型添加了
RowFirstHeight
和RowSecondHeight
两个属性,并实现了INotifyPropertyChanged
接口,如果我们更改上述属性的值,UI将自动更新。