resolve some System.Windows.Data Error
This commit is contained in:
1 parent
c259b7943d
commit
dea3287619
15 files changed
+85
-84
No files matched your search
@@ -177,6 +177,9 @@
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\UserControl\Controls\ProgressButtonDemoCtl.xaml">
|
||||
<Link>UserControl\Controls\ProgressButtonDemoCtl.xaml</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\UserControl\Controls\PropertyGridDemoCtl.xaml">
|
||||
<Link>UserControl\Controls\PropertyGridDemoCtl.xaml</Link>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\UserControl\Controls\RangeSliderDemoCtl.xaml">
|
||||
<Link>UserControl\Controls\RangeSliderDemoCtl.xaml</Link>
|
||||
</Resource>
|
||||
@@ -572,6 +575,10 @@
|
||||
<Link>UserControl\Controls\ProgressButtonDemoCtl.xaml.cs</Link>
|
||||
<DependentUpon>ProgressButtonDemoCtl.xaml</DependentUpon>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\UserControl\Controls\PropertyGridDemoCtl.xaml.cs">
|
||||
<Link>UserControl\Controls\PropertyGridDemoCtl.xaml.cs</Link>
|
||||
<DependentUpon>PropertyGridDemoCtl.xaml</DependentUpon>
|
||||
</Resource>
|
||||
<Resource Include="..\..\Shared\HandyControlDemo_Shared\UserControl\Controls\RangeSliderDemoCtl.xaml.cs">
|
||||
<Link>UserControl\Controls\RangeSliderDemoCtl.xaml.cs</Link>
|
||||
<DependentUpon>RangeSliderDemoCtl.xaml</DependentUpon>
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:extension="clr-namespace:HandyControlDemo.Tools.Extension"
|
||||
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<hc:TransitioningContentControl>
|
||||
<Grid>
|
||||
@@ -11,10 +9,10 @@
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<hc:PropertyGrid Width="500" SelectedObject="{Binding ElementName=ButtonDemo}"/>
|
||||
<hc:PropertyGrid Width="500" SelectedObject="{Binding ElementName=PathDemo}"/>
|
||||
<Border Margin="10" Background="{DynamicResource SecondaryRegionBrush}" Style="{StaticResource BorderRegion}" Grid.Column="1" Width="300">
|
||||
<hc:SimplePanel>
|
||||
<Button Name="ButtonDemo" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10" Width="200" Content="{extension:Lang Key={x:Static langs:LangKeys.Button}}"/>
|
||||
<Path Name="PathDemo" Data="{StaticResource LogoGeometry}" Stretch="Fill" MaxWidth="256" MaxHeight="256" Width="200" Height="200" Fill="#f06632" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10"/>
|
||||
</hc:SimplePanel>
|
||||
</Border>
|
||||
<hc:Divider Margin="0,20" Orientation="Vertical" LineStrokeDashArray="2,2" Grid.Column="0" HorizontalAlignment="Right"/>
|
||||
|
||||
@@ -4,16 +4,11 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class DatePropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new DateTimePicker
|
||||
{
|
||||
var picker = new DateTimePicker
|
||||
{
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
|
||||
picker.SetBinding(System.Windows.Controls.DatePicker.SelectedDateProperty, CreateBinding(propertyItem));
|
||||
|
||||
return picker;
|
||||
}
|
||||
public override DependencyProperty GetDependencyProperty() => System.Windows.Controls.DatePicker.SelectedDateProperty;
|
||||
}
|
||||
}
|
||||
+4
-9
@@ -4,16 +4,11 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class DateTimePropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new DateTimePicker
|
||||
{
|
||||
var picker = new DateTimePicker
|
||||
{
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
|
||||
picker.SetBinding(DateTimePicker.SelectedDateTimeProperty, CreateBinding(propertyItem));
|
||||
|
||||
return picker;
|
||||
}
|
||||
public override DependencyProperty GetDependencyProperty() => DateTimePicker.SelectedDateTimeProperty;
|
||||
}
|
||||
}
|
||||
@@ -6,17 +6,12 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class EnumPropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new System.Windows.Controls.ComboBox
|
||||
{
|
||||
var picker = new System.Windows.Controls.ComboBox
|
||||
{
|
||||
IsEnabled = !propertyItem.IsReadOnly,
|
||||
ItemsSource = Enum.GetValues(propertyItem.PropertyType)
|
||||
};
|
||||
IsEnabled = !propertyItem.IsReadOnly,
|
||||
ItemsSource = Enum.GetValues(propertyItem.PropertyType)
|
||||
};
|
||||
|
||||
picker.SetBinding(Selector.SelectedValueProperty, CreateBinding(propertyItem));
|
||||
|
||||
return picker;
|
||||
}
|
||||
public override DependencyProperty GetDependencyProperty() => Selector.SelectedValueProperty;
|
||||
}
|
||||
}
|
||||
+6
-11
@@ -19,18 +19,13 @@ namespace HandyControl.Controls
|
||||
|
||||
public double Maximum { get; set; }
|
||||
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new NumericUpDown
|
||||
{
|
||||
var numericUpDown = new NumericUpDown
|
||||
{
|
||||
IsReadOnly = propertyItem.IsReadOnly,
|
||||
Minimum = Minimum,
|
||||
Maximum = Maximum
|
||||
};
|
||||
IsReadOnly = propertyItem.IsReadOnly,
|
||||
Minimum = Minimum,
|
||||
Maximum = Maximum
|
||||
};
|
||||
|
||||
numericUpDown.SetBinding(NumericUpDown.ValueProperty, CreateBinding(propertyItem));
|
||||
|
||||
return numericUpDown;
|
||||
}
|
||||
public override DependencyProperty GetDependencyProperty() => NumericUpDown.ValueProperty;
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -1,19 +1,17 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class PlainTextPropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new System.Windows.Controls.TextBox
|
||||
{
|
||||
var textbox = new System.Windows.Controls.TextBox
|
||||
{
|
||||
IsReadOnly = propertyItem.IsReadOnly
|
||||
};
|
||||
IsReadOnly = propertyItem.IsReadOnly
|
||||
};
|
||||
|
||||
textbox.SetBinding(System.Windows.Controls.TextBox.TextProperty, CreateBinding(propertyItem));
|
||||
public override DependencyProperty GetDependencyProperty() => System.Windows.Controls.TextBox.TextProperty;
|
||||
|
||||
return textbox;
|
||||
}
|
||||
public override BindingMode GetBindingMode(PropertyItem propertyItem) => BindingMode.OneWay;
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,22 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public abstract FrameworkElement CreateElement(PropertyItem propertyItem);
|
||||
|
||||
public virtual Binding CreateBinding(PropertyItem propertyItem) =>
|
||||
new Binding(propertyItem.PropertyName)
|
||||
{
|
||||
Source = propertyItem.Value,
|
||||
Mode = GetBindingMode(propertyItem),
|
||||
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem)
|
||||
};
|
||||
public virtual void CreateBinding(PropertyItem propertyItem, FrameworkElement element) =>
|
||||
BindingOperations.SetBinding(element, GetDependencyProperty(),
|
||||
new Binding($"({propertyItem.PropertyName})")
|
||||
{
|
||||
Source = propertyItem.Value,
|
||||
Mode = GetBindingMode(propertyItem),
|
||||
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem),
|
||||
Converter = GetConverter()
|
||||
});
|
||||
|
||||
public abstract DependencyProperty GetDependencyProperty();
|
||||
|
||||
public virtual BindingMode GetBindingMode(PropertyItem propertyItem) => propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
|
||||
|
||||
public virtual UpdateSourceTrigger GetUpdateSourceTrigger(PropertyItem propertyItem) => UpdateSourceTrigger.PropertyChanged;
|
||||
|
||||
protected virtual IValueConverter GetConverter() => null;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class ReadOnlyTextPropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new System.Windows.Controls.TextBox
|
||||
{
|
||||
IsReadOnly = true
|
||||
};
|
||||
|
||||
public override DependencyProperty GetDependencyProperty() => System.Windows.Controls.TextBox.TextProperty;
|
||||
|
||||
public override BindingMode GetBindingMode(PropertyItem propertyItem) => BindingMode.OneWay;
|
||||
}
|
||||
}
|
||||
+6
-11
@@ -6,18 +6,13 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class SwitchPropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new ToggleButton
|
||||
{
|
||||
var button = new ToggleButton
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>("ToggleButtonSwitch"),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
Style = ResourceHelper.GetResource<Style>("ToggleButtonSwitch"),
|
||||
HorizontalAlignment = HorizontalAlignment.Left,
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
|
||||
button.SetBinding(ToggleButton.IsCheckedProperty, CreateBinding(propertyItem));
|
||||
|
||||
return button;
|
||||
}
|
||||
public override DependencyProperty GetDependencyProperty() => ToggleButton.IsCheckedProperty;
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,11 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class TimePropertyEditor : PropertyEditorBase
|
||||
{
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem)
|
||||
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new DateTimePicker
|
||||
{
|
||||
var picker = new DateTimePicker
|
||||
{
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
IsEnabled = !propertyItem.IsReadOnly
|
||||
};
|
||||
|
||||
picker.SetBinding(TimePicker.SelectedTimeProperty, CreateBinding(propertyItem));
|
||||
|
||||
return picker;
|
||||
}
|
||||
public override DependencyProperty GetDependencyProperty() => TimePicker.SelectedTimeProperty;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
@@ -128,6 +127,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
if (Editor == null) return;
|
||||
EditorElement = Editor.CreateElement(this);
|
||||
Editor.CreateBinding(this, EditorElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,8 @@ namespace HandyControl.Controls
|
||||
|
||||
public bool ResolveIsBrowsable(PropertyDescriptor propertyDescriptor) => propertyDescriptor.IsBrowsable;
|
||||
|
||||
public bool ResolveIsDisplay(PropertyDescriptor propertyDescriptor) => propertyDescriptor.IsLocalizable;
|
||||
|
||||
public bool ResolveIsReadOnly(PropertyDescriptor propertyDescriptor) => propertyDescriptor.IsReadOnly;
|
||||
|
||||
public object ResolveDefaultValue(PropertyDescriptor propertyDescriptor)
|
||||
@@ -86,13 +88,13 @@ namespace HandyControl.Controls
|
||||
EditorTypeCode.DoubleNumber => new NumberPropertyEditor(double.MinValue, double.MaxValue),
|
||||
EditorTypeCode.Switch => new SwitchPropertyEditor(),
|
||||
EditorTypeCode.DateTime => new DateTimePropertyEditor(),
|
||||
_ => new PlainTextPropertyEditor()
|
||||
_ => new ReadOnlyTextPropertyEditor()
|
||||
}
|
||||
: type.IsSubclassOf(typeof(Enum))
|
||||
? (PropertyEditorBase) new EnumPropertyEditor()
|
||||
: new PlainTextPropertyEditor();
|
||||
: new ReadOnlyTextPropertyEditor();
|
||||
|
||||
public virtual PropertyEditorBase CreateEditor(Type type) => new PlainTextPropertyEditor();
|
||||
public virtual PropertyEditorBase CreateEditor(Type type) => new ReadOnlyTextPropertyEditor();
|
||||
|
||||
private enum EditorTypeCode
|
||||
{
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Poptip.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Watermark.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\EnumPropertyEditor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\ReadOnlyTextPropertyEditor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\TimePropertyEditor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\DatePropertyEditor.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\SwitchPropertyEditor.cs" />
|
||||
|
||||
@@ -95,8 +95,8 @@
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GroupItem">
|
||||
<Expander BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource ThirdlyRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}">
|
||||
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" CornerRadius="0,0,4,4">
|
||||
<Expander BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource SecondaryRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}">
|
||||
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
|
||||
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
|
||||
</Border>
|
||||
</Expander>
|
||||
@@ -120,6 +120,8 @@
|
||||
<Setter Property="MinTitleWidth" Value="120"/>
|
||||
<Setter Property="Focusable" Value="False"/>
|
||||
<Setter Property="Padding" Value="10"/>
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="hc:PropertyGrid">
|
||||
|
||||
Reference in new issue
Block a user