Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Nov 3, 2014
2 parents 9f1d12b + e22bde0 commit c93e2ab
Show file tree
Hide file tree
Showing 24 changed files with 481 additions and 223 deletions.
13 changes: 10 additions & 3 deletions samples/XamlDesigner/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ protected override void OnStartup(StartupEventArgs e)

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;

Expand All @@ -48,7 +55,7 @@ Assembly AppDomain_CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs
ass = Assembly.Load(args.Name);
}
catch (Exception) { }

if (ass == null && args.RequestingAssembly != null) {
lastRequesting = args.RequestingAssembly.Location;
var dir = Path.GetDirectoryName(args.RequestingAssembly.Location);
Expand All @@ -68,7 +75,7 @@ Assembly AppDomain_CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs
}

internalLoad = false;

return ass;
}

Expand Down
4 changes: 2 additions & 2 deletions samples/XamlDesigner/DocumentView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 10 additions & 2 deletions samples/XamlDesigner/DocumentView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public DocumentView(Document doc)
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;
Expand All @@ -52,7 +52,15 @@ public void JumpToError(XamlError error)
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
}
}
Expand Down
29 changes: 18 additions & 11 deletions samples/XamlDesigner/ErrorListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion samples/XamlDesigner/Toolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void LoadSettings()

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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ public bool? DialogResult {
}
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>
Expand All @@ -93,15 +95,20 @@ public Window Owner {
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,27 @@ public class CollapsedWhenZero : IValueConverter

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;
Expand Down Expand Up @@ -160,37 +180,37 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
}
}

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();
Expand Down Expand Up @@ -280,7 +300,36 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
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")]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,26 @@ public abstract class OutlineNodeBase : INotifyPropertyChanged, IOutlineNode
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void InvalidateScale(out double scale, out double xOffset, out double yO
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,7 @@
<ItemGroup>
<Resource Include="Images\canvas.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Icons.32x32.EmptyProjectIcon.png" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public override DesignItemProperty ParentProperty {
/// </summary>
public override event EventHandler ParentChanged {
add { _xamlObject.ParentPropertyChanged += value; }
remove { _xamlObject.ParentPropertyChanged += value; }
remove { _xamlObject.ParentPropertyChanged -= value; }
}

public override UIElement View {
Expand Down
Loading

0 comments on commit c93e2ab

Please sign in to comment.