[英]How to resize image from text box value at runtime in WPF MVVM?
在這里,我有兩個文本框名稱LabelHeight和LabelWidth和一個圖像。我從指定給labelheight和labelwidth的默認值加載圖像。 現在我想在運行時更改那些文本框值時更改圖像高度和寬度。 我是WPF的新手。 這是我的MainViewModel類,其中我聲明了兩個帶有值的屬性
public int LabelWidth { get; set; } = 305;
public int LabelHeight { get; set; } = 200;
這是我的XML
<Image x:Name="Image"
Grid.Column="2" Grid.Row="1"
Source="Images/Norsel.bmp"
Height="{Binding LabelHeight}"
Width="{Binding LabelWidth}"
VerticalAlignment="Top"/>
<TextBox Grid.Column="1" Grid.Row="0" Margin="5" Text="{Binding LabelWidth, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding LabelHeight, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
您需要在高度和寬度上提高INotifyPropertyChanged
。
假設已在您的視圖模型上正確設置了INotifyProperChanged
,對於寬度
private int _labelWidth = 305;
public int LabelWidth
{
get { return _labelWidth; }
set
{
_labelWidth = value;
NotifyPropertyChanged("LabelWidth");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.