有人请帮忙.我有一个有趣的问题.我正在尝试实现一个MVVM应用程序,我想在我的视图中绑定到radiobuttons.
这是我的观点:
<StackPanel Orientation="Horizontal" Grid.ColumnSpan="2" >
<RadioButton GroupName="1" IsChecked="{Binding Path=NoteGeneral, Mode=TwoWay}">General</RadioButton>
<RadioButton GroupName="1" IsChecked="{Binding Path=NoteContact, Mode=TwoWay}" >Contact</RadioButton>
<RadioButton GroupName="1" IsChecked="{Binding Path=NoteAddress, Mode=TwoWay}" >Address</RadioButton>
<RadioButton GroupName="1" IsChecked="{Binding Path=NotePhone, Mode=TwoWay}" >Phone</RadioButton>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
这是我的ViewModel:
bool _NoteGeneral;
public bool NoteGeneral
{
get { return _NoteGeneral; }
set
{
_NoteGeneral = value;
OnPropertyChanged("NoteGeneral");
}
}
bool _NoteContact;
public bool NoteContact
{
get { return _NoteContact; }
set
{
_NoteContact = value;
OnPropertyChanged("NoteContact");
}
}
bool _NoteAddress;
public bool NoteAddress
{
get { return _NoteAddress; } …Run Code Online (Sandbox Code Playgroud) 是否存在双向绑定到.NET 3.5中的ToggleButton上的IsChecked属性的问题?
我有这个XAML:
<ToggleButton
Name="tbMeo"
Command="{Binding FilterOnSatelliteTypeCmd}"
IsChecked="{Binding ShowMeoDataOnly, Mode=TwoWay}"
ToolTip="Show MEO data only">
<Image Source="../images/32x32/Filter_Meo.png" Height="16" />
</ToggleButton>
Run Code Online (Sandbox Code Playgroud)
我有一个具有以下属性的ViewModel:
private bool _showMeoDataOnly;
public bool ShowMeoDataOnly
{
get { return _showMeoDataOnly; }
set
{
if (_showMeoDataOnly != value)
{
_showMeoDataOnly = value;
RaisePropertyChangedEvent("ShowMeoDataOnly");
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我单击ToggleButton,则相应地设置ShowMeoDataOnly的值.但是,如果我从后面的代码中将ShowMeoDataOnly设置为true,则ToggleButton的可视状态不会更改以指示IsChecked为true.但是,如果我手动设置ToggleButton的IsChecked属性而不是在后面的代码中将ShowMeoDataOnly设置为true,则按钮的可视状态会相应地更改.
不幸的是,切换到.NET 4/4.5现在不是一个选项,所以我无法确认这是否是.NET 3.5问题.
我的代码有什么问题吗?
我无法将两个radiobutton绑定到我的xaml表单和IsChecked属性,具有相同的组名,我也使用了nullabletoboolconverters.然而,我的代码中的radiobuttons缺血特性没有改变(一旦我们在第二个之后击中第一个放射性按钮,它根本没有达到断点)并且我正在绑定其中两个的缺血性质,因为我需要设置基于radiobuttons属性的表单上其他面板的可见性.
以下是我的xaml代码,后来是我的viewmodel.cs radiobutton属性代码:
<RadiobuttonSelectedConverter x:Key="CheckedSelection"/>// declaring my converter class in my resource dictionary.
<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="3" Margin="10,5,0,0">
<RadioButton GroupName="RadiosGroup" IsChecked="{Binding IsRadioButton1,Mode=TwoWay,
Converter={StaticResource CheckedSelection}, ConverterParameter=true}">
First</RadioButton>
<RadioButton GroupName="RadiosGroup"
Margin="40,0,0,0" IsChecked="{Binding IsRadioButton2,Mode=TwoWay,
Converter={StaticResource CheckedSelection}, ConverterParameter=true}">Second</RadioButton>
</StackPanel>
private bool _isRadioButton1;
public bool IsRadioButton1
{
get
{
return _isRadioButton1;
}
set
{
if _isRadioButton1!= value)
{
_isRadioButton1= value;
IsRadioButton2= false;
OnPropertyChanged("IsRadioButton1");
}
}
}
private bool _isRadioButton2;
public bool IsRadioButton2
{
get
{
return _isRadioButton2;
}
set
{
if (_isRadioButton2 != value)
{ …Run Code Online (Sandbox Code Playgroud) 我是一名C++开发人员,最近转向C#.我正在开发一个WPF应用程序,我需要动态生成4个单选按钮.我试图做很多RnD,但看起来这种情况很少见.
XAML:
<RadioButton Content="Base 0x" Height="16" Name="radioButton1" Width="80" />
Run Code Online (Sandbox Code Playgroud)
现在是这样的场景:我应该生成这个单选按钮4次,Content具体如下:
<RadioButton Content = Base 0x0 />
<RadioButton Content = Base 0x40 />
<RadioButton Content = Base 0x80 />
<RadioButton Content = Base 0xc0 />
Run Code Online (Sandbox Code Playgroud)
我在我的C++应用程序中完成了以下操作:
#define MAX_FPGA_REGISTERS 0x40;
for(i = 0; i < 4; i++)
{
m_registerBase[i] = new ToggleButton(String(T("Base 0x")) + String::toHexString(i * MAX_FPGA_REGISTERS));
addAndMakeVisible(m_registerBase[i]);
m_registerBase[i]->addButtonListener(this);
}
m_registerBase[0]->setToggleState(true);
Run Code Online (Sandbox Code Playgroud)
如果你在上面看到,每一次的循环中运行的内容名称将变为Base 0x0,Base 0x40,base 0x80和base 0xc0并设置第一单选按钮的切换状态为真.因此,如果您注意到所有这4个按钮都将有单按钮单击方法,并且基于索引,每个按钮都将执行操作.
我怎样才能在我的WPF应用程序中实现这一目标?:)