调整demo的combobox样式

This commit is contained in:
艾竹
2022-12-01 23:12:13 +08:00
parent 992a4bb83b
commit 503b92f40e
9 changed files with 412 additions and 159 deletions

View File

@@ -14,6 +14,7 @@
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.DiagramDesigner;component/Resources/Styles/ZoomBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.DiagramDesigner;component/Resources/Styles/DesignerItems.xaml" />
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.DiagramHelper;component/Controls/ComboBox.xaml" />
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Flowchart;component/ViewModels/FlowNode.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

View File

@@ -14,6 +14,58 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AIStudio.Wpf.Flowchart;component/ViewModels/FlowNode.xaml"/>
<ResourceDictionary>
<!-- Accent colors -->
<Color x:Key="Fluent.Ribbon.Colors.AccentBaseColor">#FF0078D7</Color>
<!--80%-->
<Color x:Key="Fluent.Ribbon.Colors.AccentColor80">#CC0078D7</Color>
<!--60%-->
<Color x:Key="Fluent.Ribbon.Colors.AccentColor60">#990078D7</Color>
<!--40%-->
<Color x:Key="Fluent.Ribbon.Colors.AccentColor40">#660078D7</Color>
<!--20%-->
<Color x:Key="Fluent.Ribbon.Colors.AccentColor20">#330078D7</Color>
<Color x:Key="Fluent.Ribbon.Colors.HighlightColor">#FF086F9E</Color>
<Color x:Key="BlackColor">#FF000000</Color>
<Color x:Key="BlackColor20">#51000000</Color>
<Color x:Key="WhiteColor">#FFFFFFFF</Color>
<Color x:Key="WhiteColor20">#51FFFFFF</Color>
<Color x:Key="Gray1">#FF333333</Color>
<Color x:Key="Gray2">#FF7F7F7F</Color>
<Color x:Key="Gray3">#FF9D9D9D</Color>
<Color x:Key="Gray4">#FFA59F93</Color>
<Color x:Key="Gray5">#FFB9B9B9</Color>
<Color x:Key="Gray6">#FFCCCCCC</Color>
<Color x:Key="Gray7">#FFD8D8D9</Color>
<Color x:Key="Gray8">#FFE0E0E0</Color>
<Color x:Key="Gray9">#5EC9C9C9</Color>
<Color x:Key="Gray10">#FFF7F7F7</Color>
<Color x:Key="TransparentWhiteColor">#00FFFFFF</Color>
<Color x:Key="Fluent.Ribbon.Colors.HighTransparentWhiteColor">#17FFFFFF</Color>
<!-- Accent brushes -->
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.AccentBaseColorBrush" Color="{StaticResource Fluent.Ribbon.Colors.AccentBaseColor}" options:Freeze="True" />
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.AccentColorBrush80" Color="{StaticResource Fluent.Ribbon.Colors.AccentColor80}" options:Freeze="True" />
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.AccentColorBrush60" Color="{StaticResource Fluent.Ribbon.Colors.AccentColor60}" options:Freeze="True" />
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.AccentColorBrush40" Color="{StaticResource Fluent.Ribbon.Colors.AccentColor40}" options:Freeze="True" />
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.AccentColorBrush20" Color="{StaticResource Fluent.Ribbon.Colors.AccentColor20}" options:Freeze="True" />
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.HighlightBrush" Color="{StaticResource Fluent.Ribbon.Colors.HighlightColor}" options:Freeze="True" />
<SolidColorBrush x:Key="WhiteBrush" Color="{StaticResource WhiteColor}" options:Freeze="True" />
<SolidColorBrush x:Key="WhiteBrush20" Color="{StaticResource WhiteColor20}" options:Freeze="True" />
<SolidColorBrush x:Key="BlackBrush" Color="{StaticResource BlackColor}" options:Freeze="True" />
<SolidColorBrush x:Key="BlackBrush20" Color="{StaticResource BlackColor20}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush1" Color="{StaticResource Gray1}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush2" Color="{StaticResource Gray2}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush3" Color="{StaticResource Gray3}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush4" Color="{StaticResource Gray4}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush5" Color="{StaticResource Gray5}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush6" Color="{StaticResource Gray6}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush7" Color="{StaticResource Gray7}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush8" Color="{StaticResource Gray8}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush9" Color="{StaticResource Gray9}" options:Freeze="True" />
<SolidColorBrush x:Key="GrayBrush10" Color="{StaticResource Gray10}" options:Freeze="True" />
<SolidColorBrush x:Key="Fluent.Ribbon.Brushes.Button.MouseOver.Background" Color="{StaticResource Fluent.Ribbon.Colors.AccentColor20}" options:Freeze="True" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
@@ -35,16 +87,15 @@
<!-- Diagram Control -->
<dd:DiagramControl Grid.Column="1" x:Name="diagram" DataContext="{Binding DiagramViewModel}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<controls:PropertiesView Grid.Column="2" SelectedObject="{Binding SelectedItem}" Width="200">
<controls:PropertiesView Grid.Column="2" CustomSetting="True" SelectedObject="{Binding SelectedItem}" Width="200">
<controls:PropertiesView.Resources>
<Color x:Key="Gray8">#FFE0E0E0</Color>
<SolidColorBrush x:Key="GrayBrush8" Color="{StaticResource Gray8}" options:Freeze="True" />
<Style x:Key="ActTypeStyle" TargetType="{x:Type ContentControl}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid DataContext="{Binding Path=DataContext,RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}">
<ComboBox BorderThickness="0" BorderBrush="Transparent" Text="{Binding ActType}" >
<ComboBox BorderThickness="0" Text="{Binding ActType}" Style="{StaticResource ComboBoxStyle}">
<ComboBoxItem Content="or"/>
<ComboBoxItem Content="and"/>
</ComboBox>
@@ -59,8 +110,8 @@
<DataTemplate>
<Grid DataContext="{Binding Path=DataContext,RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}">
<controls:MultiSelectComboBox BorderThickness="0" DisplayMemberPath="text" SelectedValuePath="value"
SelectedValues="{Binding UserIds}"
ItemsSource="{x:Static flowchart:FlowchartService.Users}" ></controls:MultiSelectComboBox>
SelectedValues="{Binding UserIds}"
ItemsSource="{Binding Path=DataContext.Users,RelativeSource={RelativeSource AncestorType={x:Type Window}}}" ></controls:MultiSelectComboBox>
</Grid>
</DataTemplate>
</Setter.Value>
@@ -72,8 +123,8 @@
<DataTemplate>
<Grid DataContext="{Binding Path=DataContext,RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}">
<controls:MultiSelectComboBox BorderThickness="0" DisplayMemberPath="text" SelectedValuePath="value"
SelectedValues="{Binding RoleIds}"
ItemsSource="{x:Static flowchart:FlowchartService.Roles}"></controls:MultiSelectComboBox>
SelectedValues="{Binding RoleIds}"
ItemsSource="{Binding Path=DataContext.Roles,RelativeSource={RelativeSource AncestorType={x:Type Window}}}"></controls:MultiSelectComboBox>
</Grid>
</DataTemplate>
</Setter.Value>
@@ -81,6 +132,6 @@
</Style>
</controls:PropertiesView.Resources>
</controls:PropertiesView>
</Grid>
</Window>

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using AIStudio.Wpf.Flowchart;
namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
{
@@ -34,6 +35,41 @@ namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
}
}
private List<SelectOption> _users = new List<SelectOption>()
{
new SelectOption(){ value = "操作员1",text = "操作员1" },
new SelectOption(){ value = "操作员2",text = "操作员2" },
new SelectOption(){ value = "Admin",text = "Admin" },
};
public List<SelectOption> Users
{
get
{
return _users;
}
set
{
_users = value;
}
}
private List<SelectOption> _roles = new List<SelectOption>()
{
new SelectOption(){ value = "操作员",text = "操作员" },
new SelectOption(){ value = "管理员",text = "管理员" },
};
public List<SelectOption> Roles
{
get
{
return _roles;
}
set
{
_roles = value;
}
}
public MainWindowViewModel()
{
ToolBoxViewModel = new ToolBoxViewModel();
@@ -58,5 +94,5 @@ namespace AIStudio.Wpf.DiagramDesigner.Test.ViewModels
}
}
}
}

View File

@@ -0,0 +1,94 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="ComboBoxStyle" TargetType="ComboBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
<Setter Property="IsSynchronizedWithCurrentItem" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton x:Name="ToggleButton" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
Grid.Column="2" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
Focusable="false"
ClickMode="Press" HorizontalContentAlignment="Left" >
<ToggleButton.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="12"/>
</Grid.ColumnDefinitions>
<Border
x:Name="Border"
Grid.ColumnSpan="2"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
<Border
x:Name="BorderComp"
Grid.Column="0"
CornerRadius="2"
Margin="1"
BorderThickness="0,0,0,0" >
<TextBlock Text="{Binding Path=Text,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}" Padding="3" />
</Border>
<Border x:Name="ArrowBorder" Grid.Column="1" >
<Path
x:Name="Arrow"
Stretch="Fill" Width="5" Height="3"
Fill="Black"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="ArrowBorder" Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Popup x:Name="Popup"
Placement="Bottom"
AllowsTransparency="True"
Focusable="False" IsOpen="{TemplateBinding IsDropDownOpen}"
PopupAnimation="Slide">
<Grid x:Name="DropDown"
SnapsToDevicePixels="True"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder"
BorderThickness="1" Background="{DynamicResource WhiteBrush}"
BorderBrush="{DynamicResource GrayBrush8}"/>
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True" DataContext="{Binding}">
<StackPanel Background="AliceBlue" IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
<Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
</Trigger>
<Trigger Property="IsDropDownOpen" Value="true">
<Setter TargetName="ToggleButton" Property="Background" Value="{DynamicResource Fluent.Ribbon.Brushes.Button.MouseOver.Background}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

View File

@@ -8,14 +8,18 @@
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True"
IsSynchronizedWithCurrentItem="True"
>
<ComboBox.ItemTemplate>
IsSynchronizedWithCurrentItem="True">
<ComboBox.Resources>
<Style TargetType="ComboBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ComboBox.Resources>
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Title}"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
Click="CheckBox_Click" />
Tag="{RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}"
Click="CheckBox_Click" />
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.Template>
@@ -63,8 +67,8 @@
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Popup x:Name="Popup"
</ToggleButton>
<Popup x:Name="Popup"
Placement="Bottom"
AllowsTransparency="True"
Focusable="False" IsOpen="{TemplateBinding IsDropDownOpen}"

View File

@@ -34,22 +34,22 @@ namespace AIStudio.Wpf.DiagramHelper.Controls
#region Dependency Properties
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(IList), typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(null,
DependencyProperty.Register(nameof(ItemsSource), typeof(IList), typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(null,
new PropertyChangedCallback(MultiSelectComboBox.OnItemsSourceChanged)));
public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(IList), typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(null,
DependencyProperty.Register(nameof(SelectedItems), typeof(IList), typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(null,
new PropertyChangedCallback(MultiSelectComboBox.OnSelectedItemsChanged)));
public static readonly DependencyProperty SelectedValuesProperty =
DependencyProperty.Register("SelectedValues", typeof(IList), typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(null,
DependencyProperty.Register(nameof(SelectedValues), typeof(IList), typeof(MultiSelectComboBox), new FrameworkPropertyMetadata(null,
new PropertyChangedCallback(MultiSelectComboBox.OnSelectedValuesChanged)));
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(MultiSelectComboBox), new UIPropertyMetadata(string.Empty));
DependencyProperty.Register(nameof(Text), typeof(string), typeof(MultiSelectComboBox), new UIPropertyMetadata(string.Empty));
public static readonly DependencyProperty DefaultTextProperty =
DependencyProperty.Register("DefaultText", typeof(string), typeof(MultiSelectComboBox), new UIPropertyMetadata(string.Empty));
DependencyProperty.Register(nameof(DefaultText), typeof(string), typeof(MultiSelectComboBox), new UIPropertyMetadata(string.Empty));
public string DisplayMemberPath { get; set; }

View File

@@ -16,11 +16,11 @@ using System.Reflection;
namespace AIStudio.Wpf.DiagramHelper.Controls
{
/// <summary>
/// Interaction logic for PropertiesView.xaml
/// </summary>
public partial class PropertiesView : UserControl
{
/// <summary>
/// Interaction logic for PropertiesView.xaml
/// </summary>
public partial class PropertiesView : UserControl
{
#region SelectedObject
public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register("SelectedObject", typeof(object), typeof(PropertiesView), new UIPropertyMetadata(null, OnSelectedObjectChanged));
@@ -70,159 +70,194 @@ namespace AIStudio.Wpf.DiagramHelper.Controls
}
}
public bool CustomSetting
{
get;
set;
}
public PropertiesView()
{
InitializeComponent();
this.Loaded += PropertiesView_Loaded;
}
{
InitializeComponent();
this.Loaded += PropertiesView_Loaded;
}
private void PropertiesView_Loaded(object sender, RoutedEventArgs e)
{
DisplayProperties();
}
DisplayProperties();
}
void PropertyChanged(object sender, PropertyChangedEventArgs e)
{
DisplayProperties();
}
{
DisplayProperties();
}
private void DisplayProperties()
{
_panel.Children.Clear();
ClearGrid();
if (SelectedObject != null)
{
int row = 0;
foreach (var prop in SelectedObject.GetType().GetProperties())
{
var attr = prop.GetCustomAttributes(typeof(BrowsableAttribute), true);
if (NeedBrowsable == false && (attr.Length == 0 || (attr[0] as BrowsableAttribute).Browsable))
{
DisplayProperty(prop, row);
row++;
}
else if(NeedBrowsable == true && (attr.Length > 0 && (attr[0] as BrowsableAttribute).Browsable))
private void DisplayProperties()
{
_panel.Children.Clear();
ClearGrid();
if (SelectedObject != null)
{
if (CustomSetting == true)
{
if (SelectedObject.GetType().GetProperty("PropertiesSetting") != null)
{
DisplayProperty(prop, row);
row++;
Dictionary<string, string> settings = SelectedObject.GetType().GetProperty("PropertiesSetting").GetValue(SelectedObject) as Dictionary<string, string>;
int row = 0;
foreach (var setting in settings)
{
var prop = SelectedObject.GetType().GetProperty(setting.Key);
DisplayProperty(prop, row, setting.Value);
row++;
}
}
}
_panel.Children.Add(_gridContainer);
}
else
{
_panel.Children.Add(_label);
}
}
else
{
int row = 0;
foreach (var prop in SelectedObject.GetType().GetProperties())
{
var attr = prop.GetCustomAttributes(typeof(BrowsableAttribute), true);
if (NeedBrowsable == false && (attr.Length == 0 || (attr[0] as BrowsableAttribute).Browsable))
{
DisplayProperty(prop, row);
row++;
}
else if (NeedBrowsable == true && (attr.Length > 0 && (attr[0] as BrowsableAttribute).Browsable))
{
DisplayProperty(prop, row);
row++;
}
}
}
_panel.Children.Add(_gridContainer);
}
else
{
_panel.Children.Add(_label);
}
}
private void ClearGrid()
{
_grid.RowDefinitions.Clear();
for (int i = _grid.Children.Count - 1; i >= 0; i--)
{
if (_grid.Children[i] != _vLine && _grid.Children[i] != _splitter)
_grid.Children.RemoveAt(i);
}
}
private void ClearGrid()
{
_grid.RowDefinitions.Clear();
for (int i = _grid.Children.Count - 1; i >= 0; i--)
{
if (_grid.Children[i] != _vLine && _grid.Children[i] != _splitter)
_grid.Children.RemoveAt(i);
}
}
private void DisplayProperty(PropertyInfo prop, int row)
{
var rowDef = new RowDefinition();
rowDef.Height = new GridLength(Math.Max(20, this.FontSize * 2));
_grid.RowDefinitions.Add(rowDef);
private void DisplayProperty(PropertyInfo prop, int row, string name = null)
{
var rowDef = new RowDefinition();
rowDef.Height = new GridLength(Math.Max(20, this.FontSize * 2));
_grid.RowDefinitions.Add(rowDef);
var tb = new TextBlock() { Text = prop.Name };
var displayAttr = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true);
if (displayAttr.Length > 0 )
if (name != null)
{
tb.Text = (displayAttr[0] as DisplayNameAttribute).DisplayName;
tb.Text = name;
tb.ToolTip = prop.Name;
}
else
{
var displayAttr = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true);
if (displayAttr.Length > 0)
{
tb.Text = (displayAttr[0] as DisplayNameAttribute).DisplayName;
tb.ToolTip = prop.Name;
}
}
tb.Margin = new Thickness(4);
tb.VerticalAlignment = VerticalAlignment.Center;
Grid.SetColumn(tb, 0);
Grid.SetRow(tb, _grid.RowDefinitions.Count - 1);
_grid.Children.Add(tb);
Grid.SetColumn(tb, 0);
Grid.SetRow(tb, _grid.RowDefinitions.Count - 1);
_grid.Children.Add(tb);
var line = new Line();
line.Style = (Style)border.Resources["gridHorizontalLineStyle"];
Grid.SetRow(line, row);
_grid.Children.Add(line);
var line = new Line();
line.Style = (Style)border.Resources["gridHorizontalLineStyle"];
Grid.SetRow(line, row);
_grid.Children.Add(line);
Style style = null;
var styleNameAttr = prop.GetCustomAttributes(typeof(StyleNameAttribute), true);
if (styleNameAttr.Length > 0)
{
style = this.FindResource((styleNameAttr[0] as StyleNameAttribute).Name) as Style;
if (style != null)
{
ContentControl content = new ContentControl();
content.Style = style;
content.DataContext = SelectedObject;
Style style = null;
var styleNameAttr = prop.GetCustomAttributes(typeof(StyleNameAttribute), true);
if (styleNameAttr.Length > 0)
{
style = this.FindResource((styleNameAttr[0] as StyleNameAttribute).Name) as Style;
if (style != null)
{
ContentControl content = new ContentControl();
content.Style = style;
content.DataContext = SelectedObject;
Grid.SetColumn(content, 1);
Grid.SetRow(content, _grid.RowDefinitions.Count - 1);
Grid.SetColumn(content, 1);
Grid.SetRow(content, _grid.RowDefinitions.Count - 1);
_grid.Children.Add(content);
}
}
if (style == null)
{
var ed = new TextBox();
ed.PreviewKeyDown += new KeyEventHandler(ed_KeyDown);
ed.Margin = new Thickness(0);
ed.VerticalAlignment = VerticalAlignment.Center;
ed.BorderThickness = new Thickness(0);
Grid.SetColumn(ed, 1);
Grid.SetRow(ed, _grid.RowDefinitions.Count - 1);
_grid.Children.Add(content);
}
}
var binding = new Binding(prop.Name);
binding.Source = SelectedObject;
binding.ValidatesOnExceptions = true;
binding.Mode = BindingMode.OneWay;
if (prop.CanWrite)
{
var mi = prop.GetSetMethod();
if (mi != null && mi.IsPublic)
binding.Mode = BindingMode.TwoWay;
}
ed.SetBinding(TextBox.TextProperty, binding);
if (style == null)
{
var ed = new TextBox();
ed.PreviewKeyDown += new KeyEventHandler(ed_KeyDown);
ed.Margin = new Thickness(0);
ed.VerticalAlignment = VerticalAlignment.Center;
ed.BorderThickness = new Thickness(0);
Grid.SetColumn(ed, 1);
Grid.SetRow(ed, _grid.RowDefinitions.Count - 1);
var template = (ControlTemplate)border.Resources["validationErrorTemplate"];
Validation.SetErrorTemplate(ed, template);
var binding = new Binding(prop.Name);
binding.Source = SelectedObject;
binding.ValidatesOnExceptions = true;
binding.Mode = BindingMode.OneWay;
if (prop.CanWrite)
{
var mi = prop.GetSetMethod();
if (mi != null && mi.IsPublic)
binding.Mode = BindingMode.TwoWay;
}
ed.SetBinding(TextBox.TextProperty, binding);
_grid.Children.Add(ed);
}
}
var template = (ControlTemplate)border.Resources["validationErrorTemplate"];
Validation.SetErrorTemplate(ed, template);
void ed_KeyDown(object sender, KeyEventArgs e)
{
var ed = sender as TextBox;
if (ed != null)
{
if (e.Key == Key.Enter)
{
ed.GetBindingExpression(TextBox.TextProperty).UpdateSource();
e.Handled = true;
}
else if (e.Key == Key.Escape)
ed.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
}
}
}
_grid.Children.Add(ed);
}
}
[AttributeUsage(AttributeTargets.Property)]
public class StyleNameAttribute : Attribute
{
private string _name;
public StyleNameAttribute(string name)
{
_name = name;
}
void ed_KeyDown(object sender, KeyEventArgs e)
{
var ed = sender as TextBox;
if (ed != null)
{
if (e.Key == Key.Enter)
{
ed.GetBindingExpression(TextBox.TextProperty).UpdateSource();
e.Handled = true;
}
else if (e.Key == Key.Escape)
ed.GetBindingExpression(TextBox.TextProperty).UpdateTarget();
}
}
}
public string Name
{
get { return _name; }
}
}
[AttributeUsage(AttributeTargets.Property)]
public class StyleNameAttribute : Attribute
{
private string _name;
public StyleNameAttribute(string name)
{
_name = name;
}
public string Name
{
get
{
return _name;
}
}
}
}

View File

@@ -96,6 +96,17 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
public string NextStepId { get; set; }
public Dictionary<string, string> SelectNextStep { get; set; } = new Dictionary<string, string>();
#endregion
public virtual Dictionary<string, string> PropertiesSetting
{
get
{
return new Dictionary<string, string>()
{
{ "Text","文本" },
};
}
}
}
public class StartFlowNode : FlowNode

View File

@@ -23,7 +23,10 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
[StyleName("UserIdsStyle")]
public List<string> UserIds
{
get { return _userIds; }
get
{
return _userIds;
}
set
{
SetProperty(ref _userIds, value);
@@ -35,7 +38,10 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
[StyleName("RoleIdsStyle")]
public List<string> RoleIds
{
get { return _roleIds; }
get
{
return _roleIds;
}
set
{
SetProperty(ref _roleIds, value);
@@ -47,7 +53,10 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
[StyleName("ActTypeStyle")]
public string ActType
{
get { return _actType; }
get
{
return _actType;
}
set
{
SetProperty(ref _actType, value);
@@ -72,6 +81,18 @@ namespace AIStudio.Wpf.Flowchart.ViewModels
}
}
public override Dictionary<string, string> PropertiesSetting
{
get
{
return new Dictionary<string, string>()
{
{ "Text","文本" },
{"UserIds", "用户" },
{"RoleIds", "角色" },
{"ActType", "or/and" }
};
}
}
}
}