本帖最后由 xu低调 于 2024-3-2 02:44 编辑
一直后端开发web api 下午没事写个wpf mvvm 的小玩意
一直没真正用过 主要是练练手devexpress
接口什么的都是网上找的 现在只做了皮皮虾(保存视频总是有片尾)
侵权删
仅限交流学习mvvm模式的开发
下载用的Masuit.Tools 可以支持多线程下载 实际测下来都是小文件 没必要
httprequest用的 restsharp
只是demo 还有很多地方可以完善 留了todo 后面大家感兴趣就尽量完善(多加几个平台) 写上注释
主要用的.net8 +devexpress
贴一下Model代码
[C#] 纯文本查看 复制代码 public partial class MainFormViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>
/// private 都是当前值
/// </summary>
private KeyValuePair<int, string> _selectedPlatformItem;
private ObservableCollection<string> _listBoxItems;
private string _validationMessage;
private string _urlInputData = "https://h5.pipix.com/s/iNwJm6jb/";
private bool _isBtnDownEnabled = false;
/// <summary>
/// public 都是控件的Binding
/// </summary>
public string ValidationMessage
{
get { return _validationMessage; }
set
{
if (_validationMessage != value)
{
_validationMessage = value;
OnPropertyChanged(nameof(ValidationMessage));
}
}
}
public Dictionary<int, string> PlatformItems { get; set; } = new();
public KeyValuePair<int, string> SelectedItem
{
get => _selectedPlatformItem;
set
{
_selectedPlatformItem = value;
// 只有当 _selectedPlatformItem 已经被初始化时才调用 OnPropertyChanged
if (_selectedPlatformItem.Key != 0)
{
OnPropertyChanged(nameof(SelectedItem));
// 在用户选择时执行其他逻辑
AddListBoxItem(value.Value);
//DXMessageBox.Show($"Selected Item: {value.Value}");
StrIsUrl();
}
else
{
_isBtnDownEnabled = false;
}
OnPropertyChanged(nameof(IsBtnDownEnabled));
}
}
public ObservableCollection<string> ListBoxItems
{
get => _listBoxItems;
set
{
_listBoxItems = value;
OnPropertyChanged(nameof(ListBoxItems));
}
}
public string UserInput
{
get => _urlInputData;
set
{
_urlInputData= value;
StrIsUrl();
OnPropertyChanged(nameof(ValidationMessage));
OnPropertyChanged(nameof(IsBtnDownEnabled));
//AddListBoxItem($"URL:{value} {ValidationMessage}");
}
}
public bool IsBtnDownEnabled
{
get => _isBtnDownEnabled;
set
{
if (_isBtnDownEnabled != value)
{
_isBtnDownEnabled = value;
OnPropertyChanged(nameof(IsBtnDownEnabled));
}
}
}
public MainFormViewModel()
{
// 初始化数据
LoadData();
// 设置默认选中第一个项
if (PlatformItems.Count > 0)
{
SelectedItem = PlatformItems.FirstOrDefault();
}
}
/// <summary>
/// 构建下拉数据
/// </summary>
private void LoadData()
{
// 这里模拟加载数据,你需要替换为实际的数据加载逻辑
PlatformItems = new Dictionary<int, string>
{
{ 0, "请选择平台" },
{ 1, "皮皮虾" },
};
_listBoxItems = new ObservableCollection<string>();
}
/// <summary>
/// 通知更改
/// </summary>
/// <param name="propertyName"></param>
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// 下拉数据源
/// </summary>
/// <param name="str"></param>
public void AddListBoxItem(string str)
{
// 添加新项到 ListBox
ListBoxItems.Add($"{DateTime.Now}: {str}");
}
private void StrIsUrl()
{
if (Uri.TryCreate(_urlInputData, UriKind.Absolute, out Uri uriResult))
{
// 检查协议是否是http或https
if (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps)
{
_isBtnDownEnabled=true;
ValidationMessage = "Valid URL";
}
else
{
_isBtnDownEnabled=false;
ValidationMessage = "Valid URL";
}
ValidationMessage = "Invalid URL";
}
else
{
_isBtnDownEnabled=false;
ValidationMessage = "Invalid URL";
}
}
}
源码
No_Mosaic.rar
(9.36 KB, 下载次数: 29)
|