随笔分类 - WPF
摘要:主要使用 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" xmlns:vm ="clr-namespace:MyApp.ViewModel" d:DataContext="{d:DesignI
阅读全文
摘要:有时候开发的窗口或控件,在运行的时候再绑定的,可以通过 d:DataContext 来绑定设计时数据。 <Window xmlns:data ="clr-namespace:WPFDemo.Model" d:DataContext="{d:DesignInstance data:DataModel
阅读全文
摘要:效果如下: 稍微组合一下: 关键资源样式如下: <Window.Resources> <Style x:Key="LabelStyle1" TargetType="{x:Type Label}"> <Setter Property="Foreground" Value="{DynamicResour
阅读全文
摘要:最终效果: 后台代码: private void Canvas_MouseMove(object sender, MouseEventArgs e) { Canvas.SetLeft(el, e.GetPosition((UIElement)sender).X - 135/2); Canvas.Se
阅读全文
摘要:目录结构: 前台xaml调用方法: <Window.Resources> <ResourceDictionary Source="Resource/Dictionary1.xaml"/> </Window.Resources> 后台代码调用方法: ResourceDictionary resourc
阅读全文
摘要:概要说明 开发过程中,很多时候都要用到一些图标。 我最常用的图标库是阿里的:www.iconfont.cn 使用方法如下: 1、搜索相关图标,并点击下载,如下图: 2、点击复制SVG代码: 3、粘贴到文本文档: <svg t="1615047957373" class="icon" viewBox=
阅读全文
摘要:要求:年龄不满18 就边框飘红 后台代码: public class AgeInfoWithValidation : IDataErrorInfo { public int Age { get; set; } public string this[string columnName] { get {
阅读全文
摘要:实现简单的年龄划分: 如果年龄小于18则显示:年龄:x,未成年人; 否则:年龄:x,成年人; 代码: [ValueConversion(typeof(int), typeof(String))] public class AgeConverter : IValueConverter { public
阅读全文
摘要:验证用户是否年满18+ public class AgeRule : ValidationRule { private Double limitAge = 18; public Double LimitAge { get { return limitAge; } set { limitAge = v
阅读全文
摘要:代码如下: DataTemplate :使用黄色着色 ControlTemplate : 使用蓝色着色 <Button Content="Button"> <Button.ContentTemplate > <DataTemplate> <Label Background="Yellow" Cont
阅读全文
摘要:很多时候,由于后台线程需要直接控制相关主线程的工作。 如果直接使用则会出现如下类似的异常: System.NotSupportedException:“该类型的 CollectionView 不支持从调度程序线程以外的线程对其 SourceCollection 进行的更改。” 方法一 在窗体初始化的
阅读全文
摘要:该方法可适用于所欲容器类型,相关属性:ClipToBounds 举例: 代码: <Canvas ClipToBounds="False" Height="100" Width="100" Background="Yellow"> <Ellipse Fill="Green" Height="100"
阅读全文
摘要:public class NotificationObject: INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void RaisePropertyChanged(string propertyName) ...
阅读全文
摘要:Imports System.ComponentModel ''' ''' 属性变化后通知UI ''' ''' Public Class NotificationObject Implements INotifyPropertyChanged Public Event PropertyChanged(sender As Object, e As PropertyC...
阅读全文
摘要:Converter:(这里实现的是将数字(默认)转换为MHz) Model层: 因为我不打算做交互所以没有ViewModel层; 直接出View层: 效果图:
阅读全文
浙公网安备 33010602011771号