【发布时间】:2012-10-22 11:11:25
【问题描述】:
我正在我的 wpf 应用程序中处理文本框和组合框。我很抱歉奇怪的标题。好吧,这是场景:
Xaml:
<ComboBox ItemsSource="{Binding PortModeList}" SelectedItem="{Binding SelectedPortModeList, Mode=OneWayToSource}" SelectedIndex="0" Name="PortModeCombo" />
<TextBox Grid.Column="1" Text="{Binding OversampleRateBox}" Name="HBFilterOversampleBox" />
ViewModel 类:
public ObservableCollection<string> PortModeList
{
get { return _PortModeList; }
set
{
_PortModeList = value;
OnPropertyChanged("PortModeList");
}
}
private string _selectedPortModeList;
public string SelectedPortModeList
{
get { return _selectedPortModeList; }
set
{
_selectedPortModeList = value;
OnPropertyChanged("SelectedPortModeList");
}
}
private string _OversampleRateBox;
public string OversampleRateBox
{
get
{
return _OversampleRateBox;
}
set
{
_OversampleRateBox = value;
OnPropertyChanged("OversampleRateBox");
}
}
这里我有三个要求:
通过使用
SelectedIdin xaml 我可以选择 id,但我想从 viewmodel 类中设置我的组合框的 selectedid。 IE。int portorder = 2 PortModeList->SetSelectedId(portOrder)。我怎么能做这样的事情?还是他们有其他方法?我需要将文本框中的条目数限制为 4。即1234在文本框中输入,它不应让用户超过4位。
我想将
OversampleRateBox中的文本格式设置为:0x__。 IE。如果用户想在变量中输入 23,那么我会将文本设置为 0x23。基本上0x应该出现在开头。
请帮忙:)
【问题讨论】:
标签: c# .net wpf combobox textbox