项目里需要实现一个表达式编辑的功能 其中可以嵌入自定义表达式参数为各种信号
如:up.Signal(10) + down.Signal(10,20,30) > 0
于是废了半天时间写了个表达式编辑器 使用的是RichTextBox 没有找到其他比较好的富文本编辑框
up.Signal(10) 和down.Signal(10,20,30) 在载入、添加表达式时翻译成黑框并根据表达式内容显示描述
<Window x:Class="WpfApp2.MainWindow"
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"
xmlns:local="clr-namespace:WpfApp2"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.ContextMenu>
<ContextMenu>
<MenuItem Header="dddd"/>
<MenuItem Header="dddd"/>
<MenuItem Header="dddd"/>
<MenuItem Header="dddd"/>
</ContextMenu>
</Window.ContextMenu>
<RichTextBox Name="RichTextBoxOutput"
VerticalContentAlignment="Center" HorizontalAlignment="Left"
Foreground="#FF4EC9B0"
IsDocumentEnabled="True"
Height="276" Margin="10,39,0,0" VerticalAlignment="Top" Width="567" FontSize="14" FontWeight="Bold">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0,1,0,1"/>
</Style>
<Style TargetType="{x:Type Run}">
<Setter Property="BaselineAlignment" Value="Center"/>
</Style>
</RichTextBox.Resources>
<FlowDocument>
<Paragraph>
<Run Text="RichTextBox"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<Button Content="添加表达式" HorizontalAlignment="Left" Margin="628,75,0,0" VerticalAlignment="Top" Width="117" Height="206" Click="Button_Click"/>
<Button Content="解析表达式" HorizontalAlignment="Left" Margin="628,296,0,0" VerticalAlignment="Top" Width="117" Height="114" Click="Button_Click_1"/>
</Grid>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
namespace WpfApp2
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
RichTextBoxOutput.Document = new FlowDocument(new Paragraph());
private void Button_Click(object sender, RoutedEventArgs e)
Border border = new Border();
border.Child = new TextBlock()
FontSize = 12,
FontStyle = FontStyles.Normal,
FontWeight = FontWeights.Normal,
Text = "表达式所指定的表达的的",
Margin = new Thickness(2, 0, 2, 0),
Foreground = new SolidColorBrush(Colors.White),
border.CornerRadius = new CornerRadius(3, 3, 3, 3);
border.BorderThickness = new Thickness(2, 2, 2, 2);
border.Background = new SolidColorBrush(Color.FromArgb(255, 30, 30, 30));
border.Opacity = 0.7;
border.Effect = new DropShadowEffect() { BlurRadius = 5, ShadowDepth = 2, Direction = -90 };
InlineUIContainer container = new InlineUIContainer(border);
container.MouseLeftButtonDown += Container_MouseLeftButtonDown1;
container.ContextMenu = this.ContextMenu;
var Paragraph = RichTextBoxOutput.Document.Blocks.LastBlock as Paragraph;
Paragraph.Inlines.Add(container);
private void Container_MouseLeftButtonDown1(object sender, MouseButtonEventArgs e)
var send = sender as InlineUIContainer;
var b = send.Child as Border;
var text = b.Child as TextBlock;
text.Text = "123456";
private void Button_Click_1(object sender, RoutedEventArgs e)
var doc = this.RichTextBoxOutput.Document;
foreach (Paragraph item in doc.Blocks)
foreach (var iline in item.Inlines)
var lpRun = iline as Run;
var lpInLine = iline as InlineUIContainer;
if (lpInLine != null)
Console.WriteLine(lpInLine.Child);
}else if (lpRun != null)
Console.WriteLine(lpRun.Text);
throw new Exception("");
鉴于 wpf 里 RichTextBox的Document 是没法在Xaml里面绑定的
于是 继承RichTextBox 重写一下 Document属性
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
public class RichTextBoxEx : RichTextBox
public new FlowDocument Document
get { return (FlowDocument)GetValue(DocumentProperty); }
set { SetValue(DocumentProperty, value); }
public static readonly DependencyProperty DocumentProperty = DependencyProperty.Register("Document", typeof(FlowDocument), typeof(RichTextBoxEx), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnDucumentChanged)));
private static void OnDucumentChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
((RichTextBox)target).Document = (FlowDocument)e.NewValue;
项目里需要实现一个表达式编辑的功能 其中可以嵌入自定义表达式参数为各种信号如:up.Signal(10) + down.Signal(10,20,30) &gt; 0于是废了半天时间写了个表达式编辑器 使用的是RichTextBox 没有找到其他比较好的富文本编辑框up.Signal(10) 和down.Signal(10,20,30) 在载入、添加表达式时翻译成黑框并根据表达式内容...
首先新建一个项目WpfEditor。
然后到Codeplex下载smithhtmleditor。
下载地址:https://archive.codeplex.com/?p=smithhtmleditor
解压后将SmithHtmlEditor文件夹整个复制。
然后粘贴到我们新建的项目中
然后将该引入Sm...
SimpleStateMachineNodeEditor
SimpleStateMachineNodeEditor是用于可视化工作和编辑状态机的WPF节点编辑器
给个星星! :star:
如果您喜欢或正在使用此项目,请给它加星号。 谢谢!
为什么选择SimpleStateMachine?
三步创建状态机:
1.在创建方案
2.使用在项目中加载方案
3.描述您的应用逻辑并运行状态机 :oncoming_automobile:
产品特点 :light_bulb:
具有Visual Studio设计的自定义窗口
状态机的两种表示
节点方案
用于节点/转换的唯一名称
对于存在没有连接的节点
添加节点和连接
撤消和重做
崩溃和移动
NodeNetwork是.NET C#WPF库,它提供节点编辑器组件。
这是计算器示例应用程序的演示:
该库的更实际的用例可以是着色器编辑器。 这是使用NodeNetwork制作的着色器编辑器示例的演示:
这些示例应用程序可在下载,其源包含在资源库中。 该库的二进制版本在NuGet上可用。
为.NET Framework 4.7.2和.NET Core 3.1或更高版本构建
开放的许可许可证。
使用现代的React式MVVM代码构建交互式,强大的控件。
正确的平移,缩放控件
自动排版系统
高度可定制,但默认情况下易于使用。
广泛的网络和连接验证支持。
表达式是一个字符串,经过解析和处理后,会返回一个值。 表达式由列/字段名称、运算符、函数和常量组成。 请参阅以下表达式示例:
“[Quantity] * [UnitPrice] * (1 - [BonusAmount])”
“[FirstName] + ‘ ‘ + [LastName]”
“[Country] == ‘USA’”
“[OrderDate] > #8/16/1994# AND [Quantity] > 20”
Ogre RTSS Node Based System
http://www.ogre3d.org/forums/viewtopic.php?f=25&t=75975&p=480098#p480098
dark_sylinc wrote:I agree on the tools. Th...
说到Sharp Development,可能很多人都不知道。这里简单介绍下,Sharp Development是一个轻量级的开源IDE,支持Python,CSharp等多种语言的程序开发。支持Silverlight、WPF的开发。同时也具备Debug功能,可以方便的调试代码。虽然它的Debug不如Visual Studio的强大,但是作为开源免费的IDE来说,还是相当不错了。
既然Sharp D
2. 在窗口中添加文本块或标签控件,用于显示确认取消弹窗的消息。
3. 添加两个按钮:一个用于确认,另一个用于取消。你可以使用WPF中的Button控件,并将其Content属性设置为“确认”和“取消”。
4. 添加事件处理程序以处理按钮的单击事件。当用户单击确认按钮时,关闭窗口并返回确认结果。当用户单击取消按钮时,关闭窗口并返回取消结果。
5. 在需要弹出确认取消弹窗的地方,实例化自定义窗口并将其显示为对话框。你可以使用WPF中的ShowDialog()方法来实现。
下面是一个示例代码片段,用于实现自定义确认取消弹窗:
```csharp
public partial class ConfirmDialog : Window
public bool Confirmed { get; private set; }
public ConfirmDialog(string message)
InitializeComponent();
Message.Text = message;
private void Confirm_Click(object sender, RoutedEventArgs e)
Confirmed = true;
Close();
private void Cancel_Click(object sender, RoutedEventArgs e)
Confirmed = false;
Close();
在需要弹出确认取消弹窗的地方,你可以这样使用它:
```csharp
var dialog = new ConfirmDialog("确定要执行此操作吗?");
if (dialog.ShowDialog() == true)
// 用户点击了确认按钮
// 用户点击了取消按钮