RyLiveTools/Source/Content/MainContent.xaml.cs
如果当时 0ec1400de9 ### 2024-04-12更新
------
####  V1.0.2404.1201
- 新增支持手动运行规则。
- 规则播放时间间隔不再针对全局声效,而只针对当前规则声效。
- 修复规则中播放文件夹可能导致无法执行的BUG。
- 修复规则不勾选礼物和点赞,则无法执行的BUG。
2024-04-13 10:13:30 +08:00

98 lines
3.0 KiB
C#

using HandyControl.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using HandyControl.Tools;
using HandyControl.Tools.Extension;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Reflection;
using System.Diagnostics.Eventing.Reader;
using System.Windows.Forms;
namespace LiveTools.Content
{
/// <summary>
/// MainContent.xaml 的交互逻辑
/// </summary>
public partial class MainContent
{
public MainContent()
{
InitializeComponent();
WeakReferenceMessenger.Default.Register<string>(this, OnReceive);
}
/// <summary>
///
/// </summary>
public object SubContent
{
get;set;
}
private rySafe.UsingLock<object> ui_lock=new rySafe.UsingLock<object>();
private List<System.Windows.Controls.UserControl> list_ui = new List<System.Windows.Controls.UserControl>();
public System.Windows.Controls.UserControl GetUI(Type type)
{
using (ui_lock.Write())
{
var find = list_ui.FindIndex(x => x.GetType() == type);
if (find == -1)
{
var ctl = (System.Windows.Controls.UserControl)Activator.CreateInstance(type);
list_ui.Add(ctl);
return ctl;
}
else
{
return list_ui[find];
}
}
}
private void OnReceive(object recipient, string message)
{
if (SubContent is IDisposable disposable)
{
disposable.Dispose();
}
switch (message)
{
case "login":
if (Config.IsLogin() == 1)
{
SubContent = GetUI(typeof(FrmAccountInfo));
}
else
{
SubContent = GetUI(typeof(FrmLogin));
}
break;
case "home":
SubContent = GetUI(typeof(FrmAccountInfo));
break;
case "rules":
SubContent = GetUI(typeof(FrmRuleView));
break;
case "direct":
SubContent = GetUI(typeof(FrmDirectView));
break;
case "setting":
SubContent = GetUI(typeof(FrmSetting));
break;
}
PresenterMain.Content= SubContent;
}
}
}