gpt4 book ai didi

silverlight-3.0 - Silverlight 3 DataForm,如何显示/隐藏字段

转载 作者:行者123 更新时间:2023-12-03 10:52:39 27 4
gpt4 key购买 nike

我有一个DataForm,它已设置要折叠的某些DataField的可见性,并且当用户从ComboBox选择一个选项时,应再次使某些DataField可见。

基本上(用粗略的伪代码)。

OnComboBoxChange = 
if this.index = 1 then
DataForm.Fields[1].Visibility = Visible
else
DataForm.Fields[2].Visibility = Visible

奖励积分适用于MVVM模式。

最佳答案

以下是使用MVVM避免代码隐藏的示例(值得商的MVVM,否):

<UserControl>
<StackPanel>
<ComboBox x:Name="comboBox" SelectionChanged="comboBox_SelectionChanged"/>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsFirstFormShown}">
<TextBlock Text="First: "/>
<TextBox/>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsSecondFormShown}">
<TextBlock Text="Second: "/>
<TextBox/>
</StackPanel>
</StackPanel>
</UserControl>

然后是您的ViewModel,
public class MyFormViewModel : INotifyPropertyChanged
{
private System.Windows.Visibility _isFirstShown;
public System.Windows.Visibility IsFirstFormShown
{
get { return _isFirstShown; }
set
{
_isFirstShown = value;
if (PropertyChanged != null )
{
PropertyChanged(this, new PropertyChangedEventArgs(value));
}
}
}

//TODO: implement the other property (writing code in this edit window makes me tired)
//hopefully you get the picture here...
}

很简单我可能会尝试为我的属性命名一些“模型”而不是“ View ”,但是这种约定并不完全不合适。

关于silverlight-3.0 - Silverlight 3 DataForm,如何显示/隐藏字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1222709/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com