Caliburn.Micro 中单选按钮的约定

发布于 2024-12-16 19:10:58 字数 182 浏览 2 评论 0原文

我发现在 WPF/MVVM 中使用单选按钮是一种有点烦人的体验。 消除 WPF 中的烦恼的“首选”答案是在 Caliburn.Micro 中寻找解决方案,或者像 CoProject 这样的配方或示例实现之一。但我找不到单选按钮约定的任何实现。当我尝试自己制作时,我意识到要让这种感觉自然且直观是多么困难。

有谁知道该公约的良好实施吗?

I find working with radiobuttons in WPF/MVVM as a slightly annoying experience.
The "go-to" answer for removing annoyances in WPF is looking for a solution in Caliburn.Micro or one of the recipes or example implementations like CoProject. But I can can not find any implementation of a convention for radiobutton. And trying to make my own I realize how hard it is to make this feel natural and intuitive.

Does anyone know of a good implementation of this convention?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我是有多爱你 2024-12-23 19:10:58

我想所以,这对你来说很有用:-

<UserControl x:Class="CaliburnMicroTest.Views.RadioButtonTestView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         d:DesignHeight="300"
         d:DesignWidth="300"
         mc:Ignorable="d">
<StackPanel>
    <RadioButton Name="NewInstallChecked"
                 Margin="75,10,0,0"
                 Content="New Installation (default)"
                 GroupName="InstallType" />
    <RadioButton Name="UpdateInstallChecked"
                 Margin="75,10,0,0"
                 Content="Update of existing Installation"
                 GroupName="InstallType" />
    <Label Name="label2"
           Height="28"
           Margin="20,20,0,0"
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Content="Please select which version of Siseco you want to install:" />
    <RadioButton Name="ServerChecked"
                 Margin="75,10,0,0"
                 Content="Server version (default)"
                 GroupName="Version" />
    <RadioButton Name="ClientChecked"
                 Margin="75,10,0,0"
                 Content="Client version"
                 GroupName="Version" />
    <StackPanel Margin="10" Orientation="Horizontal">
        <Button Name="SaveAndClose"
                Width="80"
                Content="Ok" />
        <Button Name="TryClose"
                Width="80"
                Content="Cancel" />
    </StackPanel>
</StackPanel></UserControl>




 public class RadioButtonTestViewModel : Screen
{
    private bool newInstallChecked;
    private bool updateInstallChecked;
    private bool serverChecked;
    private bool clientChecked;

    public bool NewInstallChecked
    {
        get { return newInstallChecked; }
        set
        {
            if (value.Equals(newInstallChecked)) return;
            newInstallChecked = value;
            NotifyOfPropertyChange(() => NewInstallChecked);
        }
    }

    public bool UpdateInstallChecked
    {
        get { return updateInstallChecked; }
        set
        {
            if (value.Equals(updateInstallChecked)) return;
            updateInstallChecked = value;
            NotifyOfPropertyChange(() => UpdateInstallChecked);
        }
    }

    public bool ServerChecked
    {
        get { return serverChecked; }
        set
        {
            if (value.Equals(serverChecked)) return;
            serverChecked = value;
            NotifyOfPropertyChange(() => ServerChecked);
        }
    }

    public bool ClientChecked
    {
        get { return clientChecked; }
        set
        {
            if (value.Equals(clientChecked)) return;
            clientChecked = value;
            NotifyOfPropertyChange(() => ClientChecked);
        }
    }

    public void SaveAndClose()
    {
        Options.Client = ClientChecked;
        Options.NewInstall = NewInstallChecked;

        Options.Server = ServerChecked;
        Options.UpdateInstall = UpdateInstallChecked;

        TryClose();
    }

    protected override void OnInitialize()
    {
        base.OnInitialize();

        ClientChecked = Options.Client;
        NewInstallChecked = Options.NewInstall;

        ServerChecked = Options.Server;
        UpdateInstallChecked = Options.UpdateInstall;
    }

    public static class Options
    {
        public static bool NewInstall { get; set; }
        public static bool UpdateInstall { get; set; }

        public static bool Server { get; set; }
        public static bool Client { get; set; }
    }}

I think So,This is use full to You:-

<UserControl x:Class="CaliburnMicroTest.Views.RadioButtonTestView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         d:DesignHeight="300"
         d:DesignWidth="300"
         mc:Ignorable="d">
<StackPanel>
    <RadioButton Name="NewInstallChecked"
                 Margin="75,10,0,0"
                 Content="New Installation (default)"
                 GroupName="InstallType" />
    <RadioButton Name="UpdateInstallChecked"
                 Margin="75,10,0,0"
                 Content="Update of existing Installation"
                 GroupName="InstallType" />
    <Label Name="label2"
           Height="28"
           Margin="20,20,0,0"
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Content="Please select which version of Siseco you want to install:" />
    <RadioButton Name="ServerChecked"
                 Margin="75,10,0,0"
                 Content="Server version (default)"
                 GroupName="Version" />
    <RadioButton Name="ClientChecked"
                 Margin="75,10,0,0"
                 Content="Client version"
                 GroupName="Version" />
    <StackPanel Margin="10" Orientation="Horizontal">
        <Button Name="SaveAndClose"
                Width="80"
                Content="Ok" />
        <Button Name="TryClose"
                Width="80"
                Content="Cancel" />
    </StackPanel>
</StackPanel></UserControl>




 public class RadioButtonTestViewModel : Screen
{
    private bool newInstallChecked;
    private bool updateInstallChecked;
    private bool serverChecked;
    private bool clientChecked;

    public bool NewInstallChecked
    {
        get { return newInstallChecked; }
        set
        {
            if (value.Equals(newInstallChecked)) return;
            newInstallChecked = value;
            NotifyOfPropertyChange(() => NewInstallChecked);
        }
    }

    public bool UpdateInstallChecked
    {
        get { return updateInstallChecked; }
        set
        {
            if (value.Equals(updateInstallChecked)) return;
            updateInstallChecked = value;
            NotifyOfPropertyChange(() => UpdateInstallChecked);
        }
    }

    public bool ServerChecked
    {
        get { return serverChecked; }
        set
        {
            if (value.Equals(serverChecked)) return;
            serverChecked = value;
            NotifyOfPropertyChange(() => ServerChecked);
        }
    }

    public bool ClientChecked
    {
        get { return clientChecked; }
        set
        {
            if (value.Equals(clientChecked)) return;
            clientChecked = value;
            NotifyOfPropertyChange(() => ClientChecked);
        }
    }

    public void SaveAndClose()
    {
        Options.Client = ClientChecked;
        Options.NewInstall = NewInstallChecked;

        Options.Server = ServerChecked;
        Options.UpdateInstall = UpdateInstallChecked;

        TryClose();
    }

    protected override void OnInitialize()
    {
        base.OnInitialize();

        ClientChecked = Options.Client;
        NewInstallChecked = Options.NewInstall;

        ServerChecked = Options.Server;
        UpdateInstallChecked = Options.UpdateInstall;
    }

    public static class Options
    {
        public static bool NewInstall { get; set; }
        public static bool UpdateInstall { get; set; }

        public static bool Server { get; set; }
        public static bool Client { get; set; }
    }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文