首页 > 其他分享 >WPF 中的 经典的ModelView 通知页面更新 UI

WPF 中的 经典的ModelView 通知页面更新 UI

时间:2023-06-06 16:04:42浏览次数:39  
标签:ModelView System micOff IsMuted UI StateManager using WPF public

view model

------------------------------------------------------------------------------

using HPControls.Helper;
using System;
using System.ComponentModel;
using System.Threading;
using Xiaowei.Models;
using Xiaowei.Services;
using Xiaowei.Settings;
 
namespace Xiaowei.ViewModels
{
    public class MuteViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public bool IsMuted
        {
            get { return LocalSettings.IsMuted; }
            set
            {
                if(LocalSettings.IsMuted != value)
                {
                    LocalSettings.IsMuted = value;
                    Property.Raise(this, PropertyChanged, "IsMuted");
                }
            }
        }

 

    

public void Toggle()
        {
            _ = HPMetrics.Metrics.Track(LocalSettings.CustomerId, (int)HPMetrics.XwEventType.ClickButton,"MuteButton");
   
               IsMuted = !IsMuted;
 
            _ = ApplicationModel.Current.ToggleMute(IsMuted);
            if(IsMuted)
            {
                StateManager.SetAttachState(StateManager.AttachStateEnum.micOff);
            }
            else
            {
                StateManager.RemoveAttachState(StateManager.AttachStateEnum.micOff);
            }
            
        }
 
        public static MuteViewModel Get() => LazyInstance.Value;
 
        private MuteViewModel()
        {
            Property.Raise(this, PropertyChanged, "IsMuted");
            if (IsMuted)
            {
                StateManager.SetAttachState(StateManager.AttachStateEnum.micOff);
            }
            else
            {
                StateManager.RemoveAttachState(StateManager.AttachStateEnum.micOff);
            }
        }
        
        private static readonly Lazy<MuteViewModel> LazyInstance = new Lazy<MuteViewModel>(()=>
        {
            return new MuteViewModel();
        }, LazyThreadSafetyMode.ExecutionAndPublication);
    }
}

 

 

 

 

Property 类

------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
 
namespace HPControls.Helper
{
    public static class Property
    {
        public static void Raise(object sender, PropertyChangedEventHandler handler, string property)
        {
            Run.Invoke(CoreApplication.MainView.CoreWindow.Dispatcher, () =>
            {
                handler?.Invoke(sender, new PropertyChangedEventArgs(property));
            });
        }
    }
}

标签:ModelView,System,micOff,IsMuted,UI,StateManager,using,WPF,public
From: https://blog.51cto.com/u_4018548/6425158

相关文章

  • VUE+elementUI前端导出解决方案,截断,清晰度,页边距,页眉页脚,富文本都处理了
    pdfLoader.js--------------------------/**@Description:html转pdf新版解决方案*@Author:jeseven/wwl*@Date:2023-05-2310:03:57*@LastEditTime:2023-05-2310:23:22*@LastEditors:jeseven/wwl*/importjsPDFfrom"jspdf";importhtml2canvasfrom&......
  • 记录一下elmentui中树状表单的全部展开与收缩
    html页面 <el-buttonstyle="margin-left:10px;margin-bottom:10px;"type="primary"plainsize="mini"@click="toggleRowExpansion"icon="el-icon-sort">    全部{{isExpansion?"收缩":&q......
  • 4) Builder Pattern
    类别: Creationalpattern问题: 构造函数入参超长易变方案: 示例:publicclassBuilderPatternDemo{publicstaticvoidmain(String[]args){Car.Builderbuilder=newCar.Builder("Benz");Carcar=builder.build();System.out.pri......
  • Google Guice 入门教程06 – Web 和 Servlet
    3Web和Servlet3.1快速开始我们从一个例子开始GuiceWeb的开发。首先准备我们的环境,由于是web开发,因此我们需要guice-servlet的jar包。log4j不是必须的,只是为了方便日志记录而已(Guice内部是使用jdk内部的logging包来完成日志记录的)。必可避免的要在web.xml中都一些手脚,这里先配......
  • 27) yuicompressor-maven-plugin 合并压缩 js css文件
    http://davidb.github.io/yuicompressor-maven-plugin/compress-mojo.html<plugin><groupId>net.alchim31.maven</groupId><artifactId>yuicompressor-maven-plugin</artifactId><version>1.5.1</......
  • java反编译工具jd-gui和插件jd-eclipse,还有插件Enhanced Class Decompiler 3.3.0
    JD-GUI和JD-ECLIPSE可以直接在下面的网址进行下载http://java-decompiler.github.io/ (1)注意:JD-GUI.exe单机版有很多版本,有些旧版本反编译出来的源码和高版本反编译出来的源码是区别的1.低版本的反编译可能和实际源码有出入2.1.6.6版本反编译的源码中有中文无法正常复制? ......
  • fastadmin后台引入layui
    一、首先进入官网https://layui.dev/然后点击直接下载。 二、把下载好的包放入项目libs目录下。我这里创建了一个目录叫:fastadmin-layui,然后把包里所有的文件复制到该目录下。三、修改require-backend.js文件,在paths和shim中分别添加文件路径:/public/assets/js/requ......
  • BurpSuite设置禁止显示的域名
       在做测试时,经常出现一些不想显示的域名,需要对这些域名进行禁用。通过研究发现可以通过Burpsuite自身的设置来实现,但该方法仅仅支持设置一条记录。1.详细设置方法(1)about:config(2)network.captive-portal-service.enabled输入后,单击双向按钮,修改其值由true变成false即可。......
  • 认识soui4js(第1篇)
    源代码:https://github.com/soui4js/soui4jssoui4js是soui4+quickjs的结合体。soui4是一套c++directui客户端开发框架,soui4js则将soui4的开发语言从C++迁移到了js。可能有人要问:为什么要使用js来开发?使用js开发最大的优势就是开发快速,代码写下来就可以运行,测试,同时更方便热更......
  • uniGUI学习之UniHTMLMemo1(62)
    https://blog.csdn.net/dlboy2018/article/details/82903680UniHTMLMemo1.Lines.Add("<p>"+UniHTMLMemo3.Text);//发UniHTMLMemo1.Lines.Clear();//清空输入框在这里你会发现我在发送文字处增加了“<p>”,那是因为如果不增加这个,接收窗口显示时会把多次信息链接到一起,没有换......