【发布时间】:2016-08-24 11:58:52
【问题描述】:
我正在使用模板 10 创建 UWP 应用。我已经创建了这样的用户控件。
<my:DeviceInfoUserControl OnEndpointTypeChange="{Binding OnEndpointTypeChangeCommand}" Component="{Binding DeviceManagementViewModel,Mode=TwoWay}"></my:DeviceInfoUserControl>
我在用户控件上有单选按钮。我在多个屏幕上添加了用户控制。
此用户控件有自己的 ViewModel 以及一些依赖属性,如下所示:
public class DeviceManagementViewModel : ViewModelBase
{
}
public sealed partial class DeviceInfoUserControl : UserControl
{
public bool IsToggled = true;
public DeviceInfoUserControl()
{
this.InitializeComponent();
}
public static readonly DependencyProperty OnEndpointTypeChangeProperty =
DependencyProperty.Register(
"OnEndpointTypeChange",
typeof(ICommand),
typeof(DeviceInfoUserControl), new PropertyMetadata(null));
public ICommand OnEndpointTypeChange
{
get { return (ICommand)GetValue(OnEndpointTypeChangeProperty); }
set { SetValue(OnEndpointTypeChangeProperty, value); }
}
public static readonly DependencyProperty ComponentProperty = DependencyProperty.Register("Component", typeof(DeviceManagementViewModel), typeof(DeviceInfoUserControl), new PropertyMetadata(null));
public DeviceManagementViewModel Component
{
get { return (DeviceManagementViewModel)GetValue(ComponentProperty); }
set { SetValue(ComponentProperty, value); }
}
}
我想在所有屏幕上保留单选按钮选择。我应该如何做到这一点?
【问题讨论】:
-
那么你想一键选中所有控件上的单选按钮吗?
-
是的...类似于视图模型的东西可以在全球范围内访问...所以如果我选中单选按钮,它的选择将反映到任何地方
-
SessionState 内置在 ViewModelBase 中
-
您将需要像 EventAggregator 这样的东西来传递消息。查看 Mvvm Light 示例以及消息传递示例
标签: mvvm uwp template10