jkuehner 11 years ago
parent
commit
c93e2aba69
  1. 13
      samples/XamlDesigner/App.xaml.cs
  2. 4
      samples/XamlDesigner/DocumentView.xaml
  3. 12
      samples/XamlDesigner/DocumentView.xaml.cs
  4. 29
      samples/XamlDesigner/ErrorListView.xaml
  5. 2
      samples/XamlDesigner/Toolbox.cs
  6. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  7. 33
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs
  8. 115
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs
  9. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.32x32.EmptyProjectIcon.png
  10. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs
  11. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs
  12. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  13. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  14. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  15. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Test.xaml
  16. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj
  17. 169
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs
  18. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  19. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  20. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  21. 139
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs
  22. 42
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  23. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  24. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

13
samples/XamlDesigner/App.xaml.cs

@ -31,9 +31,16 @@ namespace ICSharpCode.XamlDesigner @@ -31,9 +31,16 @@ namespace ICSharpCode.XamlDesigner
private static bool internalLoad = false;
private static string lastRequesting = null;
Assembly AppDomain_CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var assList = AppDomain.CurrentDomain.GetAssemblies();
var loaded = assList.FirstOrDefault(x => x.FullName == args.Name);
if (loaded != null)
{
return loaded;
}
if (internalLoad)
return null;
@ -48,7 +55,7 @@ namespace ICSharpCode.XamlDesigner @@ -48,7 +55,7 @@ namespace ICSharpCode.XamlDesigner
ass = Assembly.Load(args.Name);
}
catch (Exception) { }
if (ass == null && args.RequestingAssembly != null) {
lastRequesting = args.RequestingAssembly.Location;
var dir = Path.GetDirectoryName(args.RequestingAssembly.Location);
@ -68,7 +75,7 @@ namespace ICSharpCode.XamlDesigner @@ -68,7 +75,7 @@ namespace ICSharpCode.XamlDesigner
}
internalLoad = false;
return ass;
}

4
samples/XamlDesigner/DocumentView.xaml

@ -13,10 +13,10 @@ @@ -13,10 +13,10 @@
<Grid>
<AvalonEdit:TextEditor
x:Name="uxTextEditor"
SyntaxHighlighting="XML"
SyntaxHighlighting="XML" ShowLineNumbers="True"
Visibility="{Binding InXamlMode, Converter={StaticResource CollapsedWhenFalse}}" />
<ContentPresenter Content="{Binding DesignSurface}"
Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/>
Visibility="{Binding InDesignMode, Converter={StaticResource CollapsedWhenFalse}}"/>
</Grid>
</DockPanel>
</UserControl>

12
samples/XamlDesigner/DocumentView.xaml.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.XamlDesigner @@ -25,7 +25,7 @@ namespace ICSharpCode.XamlDesigner
InitializeComponent();
Document = doc;
Shell.Instance.Views[doc] = this;
Shell.Instance.Views[doc] = this;
//uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
Document.Mode = DocumentMode.Design;
@ -52,7 +52,15 @@ namespace ICSharpCode.XamlDesigner @@ -52,7 +52,15 @@ namespace ICSharpCode.XamlDesigner
try {
uxTextEditor.ScrollTo(error.Line, error.Column);
uxTextEditor.CaretOffset = uxTextEditor.Document.GetOffset(error.Line, error.Column);
} catch (ArgumentException) {
int n = 0;
char chr;
while ((chr = uxTextEditor.Document.GetCharAt(uxTextEditor.CaretOffset + n)) != ' ' && chr != '.' && chr != '<' && chr != '>' && chr != '"')
{ n++; }
uxTextEditor.SelectionLength = n;
}
catch (ArgumentException) {
// invalid line number
}
}

29
samples/XamlDesigner/ErrorListView.xaml

@ -2,15 +2,22 @@ @@ -2,15 +2,22 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Services="clr-namespace:ICSharpCode.WpfDesign.Designer.Services;assembly=ICSharpCode.WpfDesign.Designer">
<Control.Resources>
<DataTemplate DataType="{x:Type Services:XamlError}">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Error.png"
Stretch="None"
Margin="2"/>
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Control.Resources>
<Control.Resources>
<DataTemplate DataType="{x:Type Services:XamlError}">
<StackPanel Orientation="Horizontal">
<Image Source="Images/Error.png"
Stretch="None"
Margin="2"/>
<TextBlock TextAlignment="Right" Text="{Binding Line}" Width="25"
VerticalAlignment="Center"/>
<TextBlock Text=" / "
VerticalAlignment="Center"/>
<TextBlock Text="{Binding Column}" Width="25"
VerticalAlignment="Center"/>
<TextBlock Text=" - " />
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</Control.Resources>
</ListBox>

2
samples/XamlDesigner/Toolbox.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.XamlDesigner @@ -78,7 +78,7 @@ namespace ICSharpCode.XamlDesigner
static bool IsControl(Type t)
{
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement));
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(UIElement)) && t.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) != null;
}
}

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml

@ -117,17 +117,14 @@ @@ -117,17 +117,14 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:WindowClone}">
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" CornerRadius="5,5,5,5">
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1">
<DockPanel Margin="4,0,4,4">
<DockPanel Height="26" DockPanel.Dock="Top">
<Image Width="16" Height="16" Margin="1,0,0,0" Source="{TemplateBinding Window.Icon}" />
<Button Name="CloseButton" VerticalAlignment="Top" Width="43" Height="17" DockPanel.Dock="Right">
<Path Fill="#FFF6F2F2" Stretch="Uniform" Margin="1" Stroke="#FF808080" Data="M160,400 L176,400 192,384 208,400 224,400 200,376 224,352 208,352 192,368 176,352 160,352 184,376 z" />
</Button>
<Button Name="MaximiseButton" VerticalAlignment="Top" Width="25" Height="17" DockPanel.Dock="Right" />
<Button Name="MinimizeButton" VerticalAlignment="Top" Width="25" Height="17" DockPanel.Dock="Right">
<!--<Rectangle Fill="#FFF6F2F2" RadiusX="0.5" RadiusY="0.5" Width="12" Height="5" Stroke="#FF808080" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>-->
</Button>
<Image Width="16" Height="16" Margin="1,0,0,0" Source="/ICSharpCode.WpfDesign.Designer;component/Images/Icons.32x32.EmptyProjectIcon.png" Visibility="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNotNull.Instance}}" />
<Image Width="16" Height="16" Margin="1,0,0,0" Source="{TemplateBinding Window.Icon}" Visibility="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenZero.Instance}}" />
<Button Content="r" FontFamily="Marlett" Name="CloseButton" VerticalAlignment="Top" Width="43" Height="17" DockPanel.Dock="Right" />
<Button Content="1" FontFamily="Marlett" Name="MinimizeButton" VerticalAlignment="Top" Width="25" Height="17" DockPanel.Dock="Right" Visibility="{Binding ResizeMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:EnumCollapsed.Instance}, ConverterParameter=NoResize}" />
<Button Content="0" FontFamily="Marlett" Name="MaximiseButton" VerticalAlignment="Top" Width="25" Height="17" DockPanel.Dock="Right" Visibility="{Binding ResizeMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:EnumCollapsed.Instance}, ConverterParameter=NoResize}" />
<Label Margin="4,0,0,0" Content="{TemplateBinding Window.Title}" />
</DockPanel>
<Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">

33
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/WindowClone.cs

@ -66,15 +66,17 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -66,15 +66,17 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
}
set { }
}
/// <summary>
/// Specifies the icon to use.
/// </summary>
public ImageSource Icon {
get { return (ImageSource)GetValue(Window.IconProperty); }
set { SetValue(Window.IconProperty, value); }
public ImageSource Icon
{
get { return (ImageSource)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
// Using a DependencyProperty as the backing store for Icon. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register("Icon", typeof(ImageSource), typeof(WindowClone), new PropertyMetadata(null));
/// <summary>
/// This property has no effect. (for compatibility with <see cref="Window"/> only).
/// </summary>
@ -93,15 +95,20 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -93,15 +95,20 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
get { return owner; }
set { owner = value; }
}
/// <summary>
/// Gets or sets the resize mode.
/// </summary>
public ResizeMode ResizeMode {
get { return (ResizeMode)GetValue(Window.ResizeModeProperty); }
set { SetValue(Window.ResizeModeProperty, value); }
public ResizeMode ResizeMode
{
get { return (ResizeMode)GetValue(ResizeModeProperty); }
set { SetValue(ResizeModeProperty, value); }
}
// Using a DependencyProperty as the backing store for ResizeMode. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ResizeModeProperty =
DependencyProperty.Register("ResizeMode", typeof(ResizeMode), typeof(WindowClone), new PropertyMetadata(System.Windows.ResizeMode.CanResize));
/// <summary>
/// This property has no effect. (for compatibility with <see cref="Window"/> only).
/// </summary>

115
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs

@ -99,7 +99,27 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -99,7 +99,27 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || (int)value == 0) {
if (value == null || (value is int && (int)value == 0)) {
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class CollapsedWhenNotNull : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly CollapsedWhenNotNull Instance = new CollapsedWhenNotNull();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return Visibility.Collapsed;
}
return Visibility.Visible;
@ -160,37 +180,37 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -160,37 +180,37 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
}
}
public class ControlToRealWidthConverter : IMultiValueConverter
{
public static readonly ControlToRealWidthConverter Instance = new ControlToRealWidthConverter();
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return PlacementOperation.GetRealElementSize((UIElement)values[0]).Width;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class ControlToRealHeightConverter : IMultiValueConverter
{
public static readonly ControlToRealHeightConverter Instance = new ControlToRealHeightConverter();
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return PlacementOperation.GetRealElementSize((UIElement)values[0]).Height;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class FormatDoubleConverter : IValueConverter
public class ControlToRealWidthConverter : IMultiValueConverter
{
public static readonly ControlToRealWidthConverter Instance = new ControlToRealWidthConverter();
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return PlacementOperation.GetRealElementSize((UIElement)values[0]).Width;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class ControlToRealHeightConverter : IMultiValueConverter
{
public static readonly ControlToRealHeightConverter Instance = new ControlToRealHeightConverter();
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return PlacementOperation.GetRealElementSize((UIElement)values[0]).Height;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class FormatDoubleConverter : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly FormatDoubleConverter Instance=new FormatDoubleConverter();
@ -280,7 +300,36 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -280,7 +300,36 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
return Enum.Parse(targetType, parameterString);
}
}
public class EnumCollapsed : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly EnumCollapsed Instance = new EnumCollapsed();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
if (Enum.IsDefined(value.GetType(), value) == false)
return DependencyProperty.UnsetValue;
object parameterValue = Enum.Parse(value.GetType(), parameterString);
return parameterValue.Equals(value) ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
return Enum.Parse(targetType, parameterString);
}
}
public class InvertedZoomConverter : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Icons.32x32.EmptyProjectIcon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs

@ -30,15 +30,26 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -30,15 +30,26 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
protected OutlineNodeBase(DesignItem designItem)
{
DesignItem = designItem;
var hidden = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance;
bool hidden = false;
try
{
hidden = (bool)designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance;
}
catch (Exception)
{ }
if (hidden != null && (bool)hidden) {
_isDesignTimeVisible = false;
((FrameworkElement)DesignItem.Component).Visibility = Visibility.Hidden;
}
var locked = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance;
bool locked = false;
try
{
locked = (bool)designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).ValueOnInstance;
}
catch (Exception)
{ }
if (locked != null && (bool)locked) {
_isDesignTimeLocked = true;
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs

@ -133,7 +133,7 @@ namespace ICSharpCode.WpfDesign.Designer.ThumbnailView @@ -133,7 +133,7 @@ namespace ICSharpCode.WpfDesign.Designer.ThumbnailView
xOffset = 0;
yOffset = 0;
if (this.DesignSurface.DesignContext != null)
if (this.DesignSurface.DesignContext != null && this.DesignSurface.DesignContext.RootItem != null)
{
var designedElement = this.DesignSurface.DesignContext.RootItem.Component as FrameworkElement;

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -458,4 +458,7 @@ @@ -458,4 +458,7 @@
<ItemGroup>
<Resource Include="Images\canvas.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Icons.32x32.EmptyProjectIcon.png" />
</ItemGroup>
</Project>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -134,7 +134,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -134,7 +134,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
/// </summary>
public override event EventHandler ParentChanged {
add { _xamlObject.ParentPropertyChanged += value; }
remove { _xamlObject.ParentPropertyChanged += value; }
remove { _xamlObject.ParentPropertyChanged -= value; }
}
public override UIElement View {

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -107,7 +107,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -107,7 +107,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public IEnumerator<DesignItem> GetEnumerator()
{
foreach (XamlPropertyValue val in property.CollectionElements) {
yield return GetItem(val);
var item = GetItem(val);
if (item != null)
yield return item;
}
}
@ -121,7 +123,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -121,7 +123,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (val is XamlObject) {
return context._componentService.GetDesignItem( ((XamlObject)val).Instance );
} else {
throw new NotImplementedException();
return null; // throw new NotImplementedException();
}
}

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Test.xaml

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</ResourceDictionary>

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/WpfDesign.Tests.csproj

@ -102,5 +102,9 @@ @@ -102,5 +102,9 @@
<Name>WpfDesign.Designer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Page Include="Test.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>

169
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/SamplesTests.cs

@ -16,7 +16,8 @@ @@ -16,7 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.WpfDesign.XamlDom;
using NUnit.Framework;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
@ -127,7 +128,7 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -127,7 +128,7 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
}
[Test]
public void Resources()
public void Resources1()
{
TestLoading(@"<Page Name=""root""
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
@ -141,19 +142,19 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -141,19 +142,19 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Page>");
}
[Test]
public void Resources2()
{
TestLoading(@"<UserControl
[Test]
public void Resources2()
{
TestLoading(@"<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<UserControl.Resources>
<ResourceDictionary />
</UserControl.Resources>
</UserControl>");
}
}
[Test]
[Test]
public void Resources3()
{
TestLoading(@"<UserControl
@ -165,10 +166,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -165,10 +166,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</UserControl>");
}
[Test]
public void Resources4()
{
TestLoading(@"<UserControl
[Test]
public void Resources4()
{
TestLoading(@"<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<UserControl.Resources>
@ -177,8 +178,25 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -177,8 +178,25 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</ResourceDictionary>
</UserControl.Resources>
</UserControl>");
}
}
[Test]
public void Resources5()
{
TestLoading(@"<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=""/ICSharpCode.WpfDesign.Tests;component/Test.xaml"" />
</ResourceDictionary.MergedDictionaries >
</ResourceDictionary>
</UserControl.Resources>
</UserControl>");
}
[Test]
public void Animation1()
{
@ -234,7 +252,7 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -234,7 +252,7 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
[Test]
public void Animation3()
{
TestLoading(@"<Window
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -258,10 +276,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -258,10 +276,10 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Window>");
}
[Test]
public void ContentControl1()
{
TestLoading(@"<Window
[Test]
public void ContentControl1()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -270,12 +288,12 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -270,12 +288,12 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</ContentControl>
</Canvas>
</Window>");
}
}
[Test]
public void ContentControl2()
{
TestLoading(@"<Window
[Test]
public void ContentControl2()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -286,24 +304,24 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -286,24 +304,24 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</ContentControl>
</Canvas>
</Window>");
}
}
[Test]
public void Children1()
{
TestLoading(@"<Window
[Test]
public void Children1()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<Button />
</Canvas>
</Window>");
}
}
[Test]
public void Children2()
{
TestLoading(@"<Window
[Test]
public void Children2()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -312,12 +330,12 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -312,12 +330,12 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Canvas.Children>
</Canvas>
</Window>");
}
}
[Test]
public void Children3()
{
TestLoading(@"<Window
[Test]
public void Children3()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -326,12 +344,12 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom @@ -326,12 +344,12 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
</Canvas.Children>
</Canvas>
</Window>");
}
}
[Test]
public void ListBox1()
{
TestLoading(@"<Window
[Test]
public void ListBox1()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -341,13 +359,62 @@ bb @@ -341,13 +359,62 @@ bb
</ListBox>
</Canvas>
</Window>");
}
}
[Test]
//[Ignore("To fix this Test, we need a special Handling for Setter class, because MS Xaml Parser casts the Value of a Setter to the PropertyType wich is defined in another Property!")]
//Or maybe we need support for XamlSetTypeConverterAttribute, TypeConverterAttribute(typeof(SetterTriggerConditionValueConverter)), ...
public void ListBox2()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<ListBox ScrollViewer.VerticalScrollBarVisibility=""Hidden"">
<ListBox.ItemContainerStyle>
<Style TargetType=""{x:Type ListBoxItem}"">
<Setter Property=""Width"" Value=""10"" />
</Style>
</ListBox.ItemContainerStyle>
aa
bb
</ListBox>
</Canvas>
</Window>");
}
[Test]
public void CData1()
{
TestLoading(@"<Window
[Test]
public void ListBox3()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
<ListBox>
<ListBox.ItemContainerStyle>
<Style />
</ListBox.ItemContainerStyle>
<Image />
</ListBox>
</Canvas>
</Window>");
}
[Test]
public void Window1()
{
var xaml= @"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" IsActive=""true"">
</Window>";
XamlParser.Parse(new StringReader(xaml));
}
[Test]
public void CData1()
{
TestLoading(@"<Window
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<Canvas>
@ -364,6 +431,6 @@ bb @@ -364,6 +431,6 @@ bb
</x:Code>
</Canvas>
</Window>");
}
}
}
}
}

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -85,11 +85,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -85,11 +85,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else if (collectionInstance is IDictionary) {
object val = newElement.GetValueFor(null);
object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
//if (key == null || key == "") {
// if (val is Style)
// key = ((Style)val).TargetType;
//}
if (key == null || (key as string) == "")
if (key == null || key == "")
{
if (val is Style)
key = ((Style)val).TargetType;
}
if (key == null || (key as string) == "")
key = val;
((IDictionary)collectionInstance).Add(key, val);
} else {

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

@ -219,14 +219,14 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -219,14 +219,14 @@ namespace ICSharpCode.WpfDesign.XamlDom
return new XamlObject(this, xml, elementType, instance);
}
internal string GetNamespaceFor(Type type)
internal string GetNamespaceFor(Type type, bool getClrNamespace = false)
{
if (type == typeof (DesignTimeProperties))
return XamlConstants.DesignTimeNamespace;
if (type == typeof (MarkupCompatibilityProperties))
return XamlConstants.MarkupCompatibilityNamespace;
return _typeFinder.GetXmlNamespaceFor(type.Assembly, type.Namespace);
return _typeFinder.GetXmlNamespaceFor(type.Assembly, type.Namespace, getClrNamespace);
}
internal string GetPrefixForNamespace(string @namespace)

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -22,10 +22,12 @@ using System.Collections.ObjectModel; @@ -22,10 +22,12 @@ using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Markup;
using System.Xml;
using System.Windows.Data;
using System.Windows;
using System.Xaml;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -53,6 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -53,6 +55,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
this.instance = instance;
this.contentPropertyName = GetContentPropertyName(elementType);
XamlSetTypeConverter = GetTypeConverterDelegate(elementType);
ServiceProvider = new XamlObjectServiceProvider(this);
CreateWrapper();
@ -70,7 +73,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -70,7 +73,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (property.IsAttached == false) {
foreach (XamlProperty p in properties) {
if (p.IsAttached == false && p.PropertyName == property.PropertyName)
throw new XamlLoadException("duplicate property");
throw new XamlLoadException("duplicate property:" + property.PropertyName);
}
}
#endif
@ -183,7 +186,36 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -183,7 +186,36 @@ namespace ICSharpCode.WpfDesign.XamlDom
return null;
}
internal delegate void TypeConverterDelegate(Object targetObject, XamlSetTypeConverterEventArgs eventArgs);
internal TypeConverterDelegate XamlSetTypeConverter { get; private set; }
internal static TypeConverterDelegate GetTypeConverterDelegate(Type elementType)
{
var attrs = elementType.GetCustomAttributes(typeof(XamlSetTypeConverterAttribute), true) as XamlSetTypeConverterAttribute[];
if (attrs != null && attrs.Length > 0)
{
var name = attrs[0].XamlSetTypeConverterHandler;
var method=elementType.GetMethod(name, BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic);
return (TypeConverterDelegate) TypeConverterDelegate.CreateDelegate(typeof(TypeConverterDelegate), method);
}
return null;
}
private XamlType _systemXamlTypeForProperty = null;
public XamlType SystemXamlTypeForProperty
{
get
{
if (_systemXamlTypeForProperty == null)
_systemXamlTypeForProperty = new XamlType(this.ElementType, this.ServiceProvider.SchemaContext);
return _systemXamlTypeForProperty;
}
}
internal override void AddNodeTo(XamlProperty property)
{
XamlObject holder;
@ -353,7 +385,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -353,7 +385,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// Gets/Sets the name of this XamlObject.
/// </summary>
public string Name {
get
get
{
string name = GetXamlAttribute("Name");

139
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// A service provider that provides the IProvideValueTarget and IXamlTypeResolver services.
/// No other services (e.g. from the document's service provider) are offered.
/// </summary>
public class XamlObjectServiceProvider : IServiceProvider, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider
public class XamlObjectServiceProvider : IServiceProvider, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider
{
/// <summary>
/// Creates a new XamlObjectServiceProvider instance.
@ -61,12 +61,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -61,12 +61,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (serviceType == typeof(IXamlTypeResolver)) {
return Resolver;
}
if (serviceType == typeof(IXamlSchemaContextProvider)) {
return this;
}
if (serviceType == typeof(IAmbientProvider)) {
return this;
}
if (serviceType == typeof(XamlTypeResolverProvider))
{
return Resolver;
}
if (serviceType == typeof(IXamlSchemaContextProvider)) {
return this;
}
if (serviceType == typeof(IAmbientProvider)) {
return this;
}
return null;
}
@ -110,57 +114,72 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -110,57 +114,72 @@ namespace ICSharpCode.WpfDesign.XamlDom
#endregion
#region IXamlSchemaContextProvider Members
private XamlSchemaContext iCsharpXamlSchemaContext;
//Maybe we new our own XamlSchemaContext?
//private class ICsharpXamlSchemaContext : XamlSchemaContext
//{
// public override XamlType GetXamlType(Type type)
// {
// return base.GetXamlType(type);
// }
//}
public XamlSchemaContext SchemaContext
{
get
{
return iCsharpXamlSchemaContext = iCsharpXamlSchemaContext ?? new XamlSchemaContext();
}
}
#endregion
#region IAmbientProvider Members
public AmbientPropertyValue GetFirstAmbientValue(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{
return null;
}
public object GetFirstAmbientValue(params XamlType[] types)
{
return null;
}
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{
return new List<AmbientPropertyValue>();
}
public IEnumerable<object> GetAllAmbientValues(params XamlType[] types)
{
return new List<object>();
}
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, bool searchLiveStackOnly, IEnumerable<XamlType> types,
params XamlMember[] properties)
{
return new List<AmbientPropertyValue>();
}
#endregion
}
#region IXamlSchemaContextProvider Members
private XamlSchemaContext iCsharpXamlSchemaContext;
//Maybe we new our own XamlSchemaContext?
//private class ICsharpXamlSchemaContext : XamlSchemaContext
//{
// public override XamlType GetXamlType(Type type)
// {
// return base.GetXamlType(type);
// }
//}
public XamlSchemaContext SchemaContext
{
get
{
return iCsharpXamlSchemaContext = iCsharpXamlSchemaContext ?? new XamlSchemaContext();
}
}
#endregion
#region IAmbientProvider Members
public AmbientPropertyValue GetFirstAmbientValue(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{
return GetAllAmbientValues(ceilingTypes, properties).FirstOrDefault();
}
public object GetFirstAmbientValue(params XamlType[] types)
{
return null;
}
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{
var obj = this.XamlObject.ParentObject;
while (obj != null)
{
if (ceilingTypes.Any(x => obj.SystemXamlTypeForProperty.CanAssignTo(x)))
{
foreach (var pr in obj.Properties)
{
if (properties.Any(x => x.Name == pr.PropertyName))
{
yield return new AmbientPropertyValue(pr.SystemXamlMemberForProperty, pr.ValueOnInstance);
}
}
}
obj = obj.ParentObject;
}
}
public IEnumerable<object> GetAllAmbientValues(params XamlType[] types)
{
return new List<object>();
}
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, bool searchLiveStackOnly, IEnumerable<XamlType> types, params XamlMember[] properties)
{
return new List<AmbientPropertyValue>();
}
#endregion
}
}

42
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -80,6 +80,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -80,6 +80,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
throw new ArgumentNullException("reader");
return Parse(XmlReader.Create(reader), settings);
}
private XmlNode currentParsedNode;
/// <summary>
/// Parses a XAML document using an XmlReader.
@ -128,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -128,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
var root = p.ParseObject(document.DocumentElement);
p.document.ParseComplete(root);
} catch (Exception x) {
p.ReportException(x, document.DocumentElement);
p.ReportException(x, p.currentParsedNode);
}
return p.document;
@ -220,12 +222,15 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -220,12 +222,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (onlyTextNodes && numberOfTextNodes == 1) {
foreach (XmlNode childNode in element.ChildNodes) {
if (childNode.NodeType == XmlNodeType.Text) {
currentParsedNode = childNode;
initializeFromTextValueInsteadOfConstructor = (XamlTextValue)ParseValue(childNode);
}
}
}
}
currentParsedNode = element;
object instance;
if (initializeFromTextValueInsteadOfConstructor != null) {
instance = TypeDescriptor.GetConverter(elementType).ConvertFromString(
@ -284,9 +289,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -284,9 +289,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
ParseObjectAttribute(obj, attribute);
}
if (!(obj.Instance is Style)) {
ParseObjectContent(obj, element, defaultProperty, initializeFromTextValueInsteadOfConstructor);
}
ParseObjectContent(obj, element, defaultProperty, initializeFromTextValueInsteadOfConstructor);
if (iSupportInitializeInstance != null) {
iSupportInitializeInstance.EndInit();
@ -318,6 +321,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -318,6 +321,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
collectionPropertyElement = element;
} else if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
foreach (XmlNode childNode in elementChildNodes) {
currentParsedNode = childNode;
XmlElement childElement = childNode as XmlElement;
if (childElement == null || !ObjectChildElementIsPropertyElement(childElement)) {
obj.AddProperty(collectionProperty = new XamlProperty(obj, defaultProperty));
@ -328,6 +332,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -328,6 +332,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
currentParsedNode = element;
if (collectionType != null && collectionInstance == null && elementChildNodes.Count() == 1)
{
var firstChild = elementChildNodes.First() as XmlElement;
@ -344,6 +350,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -344,6 +350,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
else
{
foreach (XmlNode childNode in elementChildNodes) {
currentParsedNode = childNode;
XmlElement childElement = childNode as XmlElement;
if (childElement != null) {
if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
@ -374,6 +381,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -374,6 +381,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
}
currentParsedNode = element;
}
IEnumerable<XmlNode> GetNormalizedChildNodes(XmlElement element)
@ -412,10 +421,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -412,10 +421,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
Justification="We need to continue parsing, and the error is reported to the user.")]
XamlPropertyValue ParseValue(XmlNode childNode)
{
currentParsedNode = childNode;
try {
return ParseValueCore(childNode);
return ParseValueCore(currentParsedNode);
} catch (Exception x) {
ReportException(x, childNode);
ReportException(x, currentParsedNode);
}
return null;
}
@ -457,13 +468,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -457,13 +468,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal static XamlPropertyInfo FindProperty(object elementInstance, Type propertyType, string propertyName)
{
PropertyDescriptorCollection properties;
if (elementInstance != null) {
properties = TypeDescriptor.GetProperties(elementInstance);
} else {
properties = TypeDescriptor.GetProperties(propertyType);
}
PropertyDescriptor propertyInfo = properties[propertyName];
PropertyDescriptor propertyInfo = TypeDescriptor.GetProperties(propertyType)[propertyName];
if (propertyInfo == null && elementInstance != null)
propertyInfo = TypeDescriptor.GetProperties(elementInstance).OfType<DependencyPropertyDescriptor>().FirstOrDefault(x => x.IsAttached && x.Name == propertyName);
if (propertyInfo != null) {
return new XamlNormalPropertyInfo(propertyInfo);
} else {
@ -649,6 +658,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -649,6 +658,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
foreach (XmlNode childNode in element.ChildNodes) {
currentParsedNode = childNode;
XamlPropertyValue childValue = ParseValue(childNode);
if (childValue != null) {
if (propertyInfo.IsCollection) {
@ -669,7 +679,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -669,7 +679,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
}
currentParsedNode = element;
currentXmlSpace = oldXmlSpace;
}

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -21,8 +21,11 @@ using System.Collections.Generic; @@ -21,8 +21,11 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Windows;
using System.Windows.Markup;
using System.Xaml;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -203,7 +206,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -203,7 +206,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
propertyValue.ParentProperty = this;
propertyValue.AddNodeTo(this);
UpdateValueOnInstance();
ParentObject.OnPropertyChanged(this);
if (!wasSet) {
@ -222,13 +225,38 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -222,13 +225,38 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (PropertyValue != null) {
try {
ValueOnInstance = PropertyValue.GetValueFor(propertyInfo);
if (this.parentObject.XamlSetTypeConverter != null)
this.ParentObject.XamlSetTypeConverter(this.parentObject.Instance, new XamlSetTypeConverterEventArgs(this.SystemXamlMemberForProperty, null, ((XamlTextValue) propertyValue).Text, this.parentObject.OwnerDocument.GetTypeDescriptorContext(this.parentObject), null));
}
catch {
Debug.WriteLine("UpdateValueOnInstance() failed");
}
}
}
private XamlMember _systemXamlMemberForProperty = null;
public XamlMember SystemXamlMemberForProperty
{
get
{
if (_systemXamlMemberForProperty == null)
_systemXamlMemberForProperty = new XamlMember(this.PropertyName, SystemXamlTypeForProperty, false);
return _systemXamlMemberForProperty;
}
}
private XamlType _systemXamlTypeForProperty = null;
public XamlType SystemXamlTypeForProperty
{
get
{
if (_systemXamlTypeForProperty == null)
_systemXamlTypeForProperty = new XamlType(this.PropertyTargetType,
this.ParentObject.ServiceProvider.SchemaContext);
return _systemXamlTypeForProperty;
}
}
/// <summary>
/// Resets the properties value.
/// </summary>
@ -317,10 +345,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -317,10 +345,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
var localName = elementType.Name + "." + propertyName;
var namespaceURI = xamlDocument.GetNamespaceFor(elementType);
var clrNamespaceURI = xamlDocument.GetNamespaceFor(elementType, true);
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == localName && childNode.NamespaceURI == namespaceURI)
if (childNode.LocalName == localName && (childNode.NamespaceURI == namespaceURI || childNode.NamespaceURI == clrNamespaceURI))
{
return childNode;
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

@ -117,11 +117,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -117,11 +117,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// <summary>
/// Gets the XML namespace that can be used for the specified assembly/namespace combination.
/// </summary>
public string GetXmlNamespaceFor(Assembly assembly, string @namespace)
public string GetXmlNamespaceFor(Assembly assembly, string @namespace, bool getClrNamespace = false)
{
AssemblyNamespaceMapping mapping = new AssemblyNamespaceMapping(assembly, @namespace);
string xmlNamespace;
if (reverseDict.TryGetValue(mapping, out xmlNamespace)) {
if (!getClrNamespace && reverseDict.TryGetValue(mapping, out xmlNamespace)) {
return xmlNamespace;
} else {
return "clr-namespace:" + mapping.Namespace + ";assembly=" + mapping.Assembly.GetName().Name;

Loading…
Cancel
Save