Browse Source

- Fix in-place editor placement and resolve issue when resizing while editing text too;caused an exception due to nested transactions.

- Highlight text that can be edited with a border.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6337 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 16 years ago
parent
commit
89ec55d12f
  1. 540
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  2. 138
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/InPlaceEditor.cs
  3. 91
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs
  4. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs

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

@ -1,105 +1,60 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" xmlns:ControlConvertors="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls.Converters" xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
xmlns:ControlConvertors="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls.Converters"
xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters">
<!-- <!--
This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls
--> -->
<Converters:LevelConverter x:Key="FormatDoubleConverter" /> <Converters:LevelConverter x:Key="FormatDoubleConverter" />
<ControlConvertors:HandleLengthWithOffset x:Key="HandleLengthWithOffset"/> <ControlConvertors:HandleLengthWithOffset x:Key="HandleLengthWithOffset" />
<SolidColorBrush Color="#FF474747" x:Key="HandleBrush" />
<SolidColorBrush Color="#FF474747" x:Key="HandleBrush"/>
<Style TargetType="{x:Type Controls:PanelMoveAdorner}"> <Style TargetType="{x:Type Controls:PanelMoveAdorner}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:PanelMoveAdorner}"> <ControlTemplate TargetType="{x:Type Controls:PanelMoveAdorner}">
<Border BorderThickness="4" <Border BorderThickness="4" Margin="-2" BorderBrush="Transparent" Cursor="SizeAll" />
Margin="-2"
BorderBrush="Transparent"
Cursor="SizeAll" />
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:EnumButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Style TargetType="{x:Type Controls:EnumButton}" <Setter Property="Margin" Value="3 3 0 3" />
BasedOn="{StaticResource {x:Type ToggleButton}}"> <Setter Property="MinWidth" Value="50" />
<Setter Property="Margin"
Value="3 3 0 3" />
<Setter Property="MinWidth"
Value="50" />
</Style> </Style>
<Style TargetType="{x:Type Controls:ResizeThumb}"> <Style TargetType="{x:Type Controls:ResizeThumb}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ResizeThumb}"> <ControlTemplate TargetType="{x:Type Controls:ResizeThumb}">
<Rectangle Name="thumbRectangle" <Rectangle Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="Black" Fill="White" RadiusX="1.414" RadiusY="1.414" />
SnapsToDevicePixels="True"
Stroke="Black"
Fill="White"
RadiusX="1.414"
RadiusY="1.414" />
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsPrimarySelection" <Trigger Property="IsPrimarySelection" Value="False">
Value="False"> <Setter TargetName="thumbRectangle" Property="Stroke" Value="White" />
<Setter TargetName="thumbRectangle" <Setter TargetName="thumbRectangle" Property="Fill" Value="Black" />
Property="Stroke"
Value="White" />
<Setter TargetName="thumbRectangle"
Property="Fill"
Value="Black" />
</Trigger> </Trigger>
<Trigger Property="IsEnabled" <Trigger Property="IsEnabled" Value="False">
Value="False"> <Setter TargetName="thumbRectangle" Property="Fill" Value="Gray" />
<Setter TargetName="thumbRectangle"
Property="Fill"
Value="Gray" />
</Trigger> </Trigger>
<Trigger Property="ResizeThumbVisible" <Trigger Property="ResizeThumbVisible" Value="False">
Value="False"> <Setter TargetName="thumbRectangle" Property="Visibility" Value="Hidden" />
<Setter TargetName="thumbRectangle"
Property="Visibility"
Value="Hidden" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:SelectionFrame}"> <Style TargetType="{x:Type Controls:SelectionFrame}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:SelectionFrame}"> <ControlTemplate TargetType="{x:Type Controls:SelectionFrame}">
<Rectangle Fill="#519ABFE5" <Rectangle Fill="#519ABFE5" Stroke="#FF7A8787" StrokeThickness="1" />
Stroke="#FF7A8787"
StrokeThickness="1" />
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:ContainerDragHandle}"> <Style TargetType="{x:Type Controls:ContainerDragHandle}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ContainerDragHandle}"> <ControlTemplate TargetType="{x:Type Controls:ContainerDragHandle}">
<Canvas Height="13" <Canvas Height="13" Width="13" Name="Canvas" SnapsToDevicePixels="True">
Width="13" <Rectangle Height="13" Width="13" RadiusX="2" RadiusY="2" Fill="#889ABFE5" Name="BorderRectangle" Stroke="#FF7A8FB5" StrokeThickness="1" />
Name="Canvas" <Path Fill="#FF748EAA" Canvas.Left="1" Canvas.Top="1">
SnapsToDevicePixels="True">
<Rectangle Height="13"
Width="13"
RadiusX="2"
RadiusY="2"
Fill="#889ABFE5"
Name="BorderRectangle"
Stroke="#FF7A8FB5"
StrokeThickness="1" />
<Path Fill="#FF748EAA"
Canvas.Left="1"
Canvas.Top="1">
<Path.Data> <Path.Data>
<GeometryGroup> <GeometryGroup>
<PathGeometry Figures="M5.5,0L3,3L8,3 M11,5.5L8,3L8,8 M5.5,11L3,8L8,8 M0,5.5L3,3L3,8" /> <PathGeometry Figures="M5.5,0L3,3L8,3 M11,5.5L8,3L8,8 M5.5,11L3,8L8,8 M0,5.5L3,3L3,8" />
@ -114,59 +69,29 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:WindowClone}"> <Style TargetType="{x:Type Controls:WindowClone}">
<Setter Property="Width" <Setter Property="Width" Value="640" />
Value="640" /> <Setter Property="Height" Value="480" />
<Setter Property="Height"
Value="480" />
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:WindowClone}"> <ControlTemplate TargetType="{x:Type Controls:WindowClone}">
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" <Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" CornerRadius="5,5,5,5">
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
BorderThickness="1,1,1,1"
CornerRadius="5,5,5,5">
<DockPanel Margin="4,0,4,4"> <DockPanel Margin="4,0,4,4">
<DockPanel Height="26" <DockPanel Height="26" DockPanel.Dock="Top">
DockPanel.Dock="Top"> <Image Width="16" Height="16" Margin="1,0,0,0" Source="{TemplateBinding Window.Icon}" />
<Image Width="16" <Button Name="CloseButton" VerticalAlignment="Top" Width="43" Height="17" DockPanel.Dock="Right">
Height="16" <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" />
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>
<Button Name="MaximiseButton" <Button Name="MaximiseButton" VerticalAlignment="Top" Width="25" Height="17" DockPanel.Dock="Right" />
VerticalAlignment="Top" <Button Name="MinimizeButton" VerticalAlignment="Top" Width="25" Height="17" DockPanel.Dock="Right">
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"/>--> <!--<Rectangle Fill="#FFF6F2F2" RadiusX="0.5" RadiusY="0.5" Width="12" Height="5" Stroke="#FF808080" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>-->
</Button> </Button>
<Label Margin="4,0,0,0" <Label Margin="4,0,0,0" Content="{TemplateBinding Window.Title}" />
Content="{TemplateBinding Window.Title}" />
</DockPanel> </DockPanel>
<Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"> <Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<Border BorderBrush="{TemplateBinding Border.BorderBrush}" <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Background="{TemplateBinding Panel.Background}">
BorderThickness="{TemplateBinding Border.BorderThickness}"
Background="{TemplateBinding Panel.Background}">
<AdornerDecorator> <AdornerDecorator>
<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" <ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" Content="{TemplateBinding ContentControl.Content}" />
Content="{TemplateBinding ContentControl.Content}" />
</AdornerDecorator> </AdornerDecorator>
</Border> </Border>
</Border> </Border>
@ -176,16 +101,11 @@
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:ErrorBalloon}"> <Style TargetType="{x:Type Controls:ErrorBalloon}">
<Setter Property="WindowStyle" <Setter Property="WindowStyle" Value="None" />
Value="None" /> <Setter Property="AllowsTransparency" Value="True" />
<Setter Property="AllowsTransparency" <Setter Property="SizeToContent" Value="WidthAndHeight" />
Value="True" /> <Setter Property="ShowInTaskbar" Value="False" />
<Setter Property="SizeToContent"
Value="WidthAndHeight" />
<Setter Property="ShowInTaskbar"
Value="False" />
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ErrorBalloon}"> <ControlTemplate TargetType="{x:Type Controls:ErrorBalloon}">
@ -193,50 +113,25 @@
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Rectangle RadiusX="10" <Rectangle RadiusX="10" RadiusY="10" Margin="12,36,4,4">
RadiusY="10"
Margin="12,36,4,4">
<Rectangle.Fill> <Rectangle.Fill>
<SolidColorBrush Color="#41626262" /> <SolidColorBrush Color="#41626262" />
</Rectangle.Fill> </Rectangle.Fill>
</Rectangle> </Rectangle>
<Border Margin="8,32,8,8" <Border Margin="8,32,8,8" Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" CornerRadius="10,10,10,10" Padding="10,10,10,10">
Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Background="{TemplateBinding Panel.Background}">
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
BorderThickness="1,1,1,1"
CornerRadius="10,10,10,10"
Padding="10,10,10,10">
<Border BorderBrush="{TemplateBinding Border.BorderBrush}"
BorderThickness="{TemplateBinding Border.BorderThickness}"
Background="{TemplateBinding Panel.Background}">
<AdornerDecorator> <AdornerDecorator>
<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" <ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" Content="{TemplateBinding ContentControl.Content}" />
Content="{TemplateBinding ContentControl.Content}" />
</AdornerDecorator> </AdornerDecorator>
</Border> </Border>
</Border> </Border>
<Path Fill="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" <Path Fill="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" Stretch="Fill" HorizontalAlignment="Left" Margin="34.75,9.25,0,0" VerticalAlignment="Top" Width="15.25" Height="24.5" Data="M34.75,33.75 L40.5,9.25 50,33.5 z" />
Stretch="Fill" <Path Stretch="Fill" Stroke="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" HorizontalAlignment="Left" Margin="34.5,9.25,0,0" VerticalAlignment="Top" Width="16" Height="24" Data="M35,32.75 L40.5,9.25 50,32.75" />
HorizontalAlignment="Left"
Margin="34.75,9.25,0,0"
VerticalAlignment="Top"
Width="15.25"
Height="24.5"
Data="M34.75,33.75 L40.5,9.25 50,33.5 z" />
<Path Stretch="Fill"
Stroke="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
HorizontalAlignment="Left"
Margin="34.5,9.25,0,0"
VerticalAlignment="Top"
Width="16"
Height="24"
Data="M35,32.75 L40.5,9.25 50,32.75" />
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:GridRowSplitterAdorner}"> <Style TargetType="{x:Type Controls:GridRowSplitterAdorner}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -249,40 +144,22 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle --> <!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle -->
<Rectangle Fill="Transparent" /> <Rectangle Fill="Transparent" />
<Path Name="railHandle" <Path Name="railHandle" Fill="#FFE6E6FF" Stretch="Fill" Stroke="#FF584FFF" Data="M0,0 L0,1 1,0.5 z" />
Fill="#FFE6E6FF" <Path Name="line" Stretch="Fill" Stroke="#FF584FFF" Grid.Column="2" Margin="-1 0 0 0" Data="M0,0.5 L1,0.5" />
Stretch="Fill"
Stroke="#FF584FFF"
Data="M0,0 L0,1 1,0.5 z" />
<Path Name="line"
Stretch="Fill"
Stroke="#FF584FFF"
Grid.Column="2"
Margin="-1 0 0 0"
Data="M0,0.5 L1,0.5" />
</Grid> </Grid>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" <Trigger Property="IsMouseOver" Value="True">
Value="True"> <Setter TargetName="railHandle" Property="Fill" Value="#FFFFB74F" />
<Setter TargetName="railHandle"
Property="Fill"
Value="#FFFFB74F" />
</Trigger> </Trigger>
<Trigger Property="IsPreview" <Trigger Property="IsPreview" Value="True">
Value="True"> <Setter TargetName="railHandle" Property="Stroke" Value="#D0FFB74F" />
<Setter TargetName="railHandle" <Setter TargetName="line" Property="Stroke" Value="#D0FFB74F" />
Property="Stroke"
Value="#D0FFB74F" />
<Setter TargetName="line"
Property="Stroke"
Value="#D0FFB74F" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:GridColumnSplitterAdorner}"> <Style TargetType="{x:Type Controls:GridColumnSplitterAdorner}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
@ -295,226 +172,135 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle --> <!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle -->
<Rectangle Fill="Transparent" /> <Rectangle Fill="Transparent" />
<Path Name="railHandle" <Path Name="railHandle" Fill="#FFE6E6FF" Stretch="Fill" Stroke="#FF584FFF" Data="M0,0 L1,0 0.5,1 z" />
Fill="#FFE6E6FF" <Path Name="line" Stretch="Fill" Stroke="#FF584FFF" Grid.Row="2" Margin="0 -1 0 0" Data="M0.5,0 L0.5,1" />
Stretch="Fill"
Stroke="#FF584FFF"
Data="M0,0 L1,0 0.5,1 z" />
<Path Name="line"
Stretch="Fill"
Stroke="#FF584FFF"
Grid.Row="2"
Margin="0 -1 0 0"
Data="M0.5,0 L0.5,1" />
</Grid> </Grid>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" <Trigger Property="IsMouseOver" Value="True">
Value="True"> <Setter TargetName="railHandle" Property="Fill" Value="#FFFFB74F" />
<Setter TargetName="railHandle"
Property="Fill"
Value="#FFFFB74F" />
</Trigger> </Trigger>
<Trigger Property="IsPreview" <Trigger Property="IsPreview" Value="True">
Value="True"> <Setter TargetName="railHandle" Property="Stroke" Value="#D0FFB74F" />
<Setter TargetName="railHandle" <Setter TargetName="line" Property="Stroke" Value="#D0FFB74F" />
Property="Stroke"
Value="#D0FFB74F" />
<Setter TargetName="line"
Property="Stroke"
Value="#D0FFB74F" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:MarginHandle}"> <Style TargetType="{x:Type Controls:MarginHandle}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:MarginHandle}"> <ControlTemplate TargetType="{x:Type Controls:MarginHandle}">
<Grid Height="10" Width="{Binding Path=HandleLength, Converter={x:Static ControlConvertors:HandleLengthWithOffset.Instance}, RelativeSource={RelativeSource Mode=TemplatedParent}}" SnapsToDevicePixels="True"> <Grid Height="10" Width="{Binding Path=HandleLength, Converter={x:Static ControlConvertors:HandleLengthWithOffset.Instance}, RelativeSource={RelativeSource Mode=TemplatedParent}}" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="8" /> <ColumnDefinition Width="8" />
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Path Name="startArrow" <Path Name="startArrow" Fill="{StaticResource HandleBrush}" Stretch="Fill" Stroke="{TemplateBinding Panel.Background}" StrokeThickness="0.5" Margin="0,1,0,1" Data="M0,0 L0,1 1,0.5 z" Grid.Column="0" />
Fill="{StaticResource HandleBrush}" <!-- Wrap the handle-line and endArrow in this grid. It's visiblity is subjected to HandleLength -->
Stretch="Fill" <Grid Height="10" Grid.Column="1" Name="lineArrow">
Stroke="{TemplateBinding Panel.Background}" <Grid.ColumnDefinitions>
StrokeThickness="0.5" <ColumnDefinition Width="*" />
Margin="0,1,0,1" <ColumnDefinition MaxWidth="20" MinWidth="10" />
Data="M0,0 L0,1 1,0.5 z" Grid.Column="0" /> <ColumnDefinition Width="*" />
<!-- Wrap the handle-line and endArrow in this grid. It's visiblity is subjected to HandleLength --> <ColumnDefinition Width="8" />
<Grid Height="10" Grid.Column="1" Name="lineArrow"> </Grid.ColumnDefinitions>
<Grid.ColumnDefinitions> <Rectangle Fill="Transparent" Height="10" Grid.Column="0" Grid.ColumnSpan="4" />
<ColumnDefinition Width="*" /> <Path Name="line1" Stretch="Fill" Stroke="{StaticResource HandleBrush}" StrokeThickness="1.5" Margin="0 0 0 0" Data="M0,-0.75 L1,-0.75" Grid.Column="0" />
<ColumnDefinition MaxWidth="20" MinWidth="10" /> <TextBlock Grid.Column="1" Text="{Binding Path=HandleLength, Mode=OneWay, Converter={x:Static Converters:FormatDoubleConverter.Instance }, RelativeSource={RelativeSource Mode=TemplatedParent}}" FontSize="9" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="1,1,1,1">
<ColumnDefinition Width="*" /> <TextBlock.LayoutTransform>
<ColumnDefinition Width="8" /> <RotateTransform Angle="{Binding Path=TextTransform, RelativeSource={RelativeSource Mode=TemplatedParent}}" CenterX="0.5" CenterY="0.5">
</Grid.ColumnDefinitions> </RotateTransform>
<Rectangle Fill="Transparent" Height="10" Grid.Column="0" Grid.ColumnSpan="4"/> </TextBlock.LayoutTransform>
<Path Name="line1" </TextBlock>
Stretch="Fill" <Path Name="line2" Stretch="Fill" Stroke="{StaticResource HandleBrush}" StrokeThickness="1.5" Margin="0 0 0 0" Data="M0,-0.75 L1,-0.75" Grid.Column="2" />
Stroke="{StaticResource HandleBrush}" <Path Name="arrow2" Margin="0,1,0,1" Fill="{StaticResource HandleBrush}" Stretch="Fill" Stroke="{TemplateBinding Panel.Background}" StrokeThickness="0.5" Data="M0,0 L0,1 1,0.5 z" Grid.Column="3" />
StrokeThickness="1.5" </Grid>
Margin="0 0 0 0" <!-- Rotate the handle and angle of rotation being set by the Margin type. See enum HandleOrientation -->
Data="M0,-0.75 L1,-0.75" Grid.Column="0"/> <Grid.LayoutTransform>
<TextBlock Grid.Column="1" <RotateTransform Angle="{Binding Path=Angle, RelativeSource={RelativeSource Mode=TemplatedParent}}">
Text="{Binding Path=HandleLength, Mode=OneWay, Converter={x:Static Converters:FormatDoubleConverter.Instance }, RelativeSource={RelativeSource Mode=TemplatedParent}}" </RotateTransform>
FontSize="9" </Grid.LayoutTransform>
VerticalAlignment="Center" </Grid>
HorizontalAlignment="Center" </ControlTemplate>
Padding="1,1,1,1"> </Setter.Value>
<TextBlock.LayoutTransform> </Setter>
<RotateTransform Angle="{Binding Path=TextTransform, RelativeSource={RelativeSource Mode=TemplatedParent}}" CenterX="0.5" CenterY="0.5"> </Style>
</RotateTransform> <Style TargetType="{x:Type Controls:MarginStub}">
</TextBlock.LayoutTransform> <Setter Property="Template">
</TextBlock> <Setter.Value>
<Path Name="line2" <ControlTemplate TargetType="{x:Type Controls:MarginStub}">
Stretch="Fill" <Grid SnapsToDevicePixels="True" Height="10" Width="10">
Stroke="{StaticResource HandleBrush}" <Rectangle Fill="Transparent" />
StrokeThickness="1.5" <Ellipse Fill="{TemplateBinding Panel.Background}" Height="7" Width="7" StrokeThickness="1" Stroke="{StaticResource HandleBrush}" />
Margin="0 0 0 0" </Grid>
Data="M0,-0.75 L1,-0.75" Grid.Column="2"/> </ControlTemplate>
<Path Name="arrow2" </Setter.Value>
Margin="0,1,0,1" </Setter>
Fill="{StaticResource HandleBrush}" </Style>
Stretch="Fill"
Stroke="{TemplateBinding Panel.Background}"
StrokeThickness="0.5"
Data="M0,0 L0,1 1,0.5 z" Grid.Column="3" />
</Grid>
<!-- Rotate the handle and angle of rotation being set by the Margin type. See enum HandleOrientation -->
<Grid.LayoutTransform>
<RotateTransform Angle="{Binding Path=Angle, RelativeSource={RelativeSource Mode=TemplatedParent}}"></RotateTransform>
</Grid.LayoutTransform>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:MarginStub}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:MarginStub}">
<Grid SnapsToDevicePixels="True" Height="10" Width="10">
<Rectangle Fill="Transparent"/>
<Ellipse
Fill="{TemplateBinding Panel.Background}"
Height="7"
Width="7"
StrokeThickness="1"
Stroke="{StaticResource HandleBrush}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:HeightDisplay}"> <Style TargetType="{x:Type Controls:HeightDisplay}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:HeightDisplay}"> <ControlTemplate TargetType="{x:Type Controls:HeightDisplay}">
<Grid Width="22" > <Grid Width="22">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition MaxHeight="20" MinHeight="5" /> <RowDefinition MaxHeight="20" MinHeight="5" />
<RowDefinition Height="5" /> <RowDefinition Height="5" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Path SnapsToDevicePixels="True" <Path SnapsToDevicePixels="True" Grid.Row="0" Stroke="#AC0000" StrokeThickness="1.0" Data="M0,0 L1,0 M0.75,0 L0.75,1" Stretch="Fill" />
Grid.Row="0" <TextBlock Text="{Binding Path=ActualHeight, Converter={x:Static Converters:FormatDoubleConverter.Instance}}" HorizontalAlignment="Center" Margin="8,0,0,1" Padding="1,1,1,1" FontSize="10" Grid.Row="1">
Stroke="#AC0000" <TextBlock.LayoutTransform>
StrokeThickness="1.0" <RotateTransform Angle="270" CenterX="0.5" CenterY="0.5" />
Data="M0,0 L1,0 M0.75,0 L0.75,1" </TextBlock.LayoutTransform>
Stretch="Fill" /> </TextBlock>
<TextBlock Text="{Binding Path=ActualHeight, Converter={x:Static Converters:FormatDoubleConverter.Instance}}" <Path SnapsToDevicePixels="True" Grid.Row="2" Stroke="#AC0000" StrokeThickness="1.0" Data="M0.75,0 L0.75,3 M0,3 L1,3 " Stretch="Fill" />
HorizontalAlignment="Center" </Grid>
Margin="8,0,0,1" </ControlTemplate>
Padding="1,1,1,1" </Setter.Value>
FontSize="10" </Setter>
Grid.Row="1"> </Style>
<TextBlock.LayoutTransform> <Style TargetType="{x:Type Controls:WidthDisplay}">
<RotateTransform Angle="270" CenterX="0.5" CenterY="0.5"/> <Setter Property="Template">
</TextBlock.LayoutTransform></TextBlock> <Setter.Value>
<Path SnapsToDevicePixels="True" <ControlTemplate TargetType="{x:Type Controls:WidthDisplay}">
Grid.Row="2" <Grid Height="22" SnapsToDevicePixels="True">
Stroke="#AC0000" <Grid.ColumnDefinitions>
StrokeThickness="1.0" <ColumnDefinition Width="*" />
Data="M0.75,0 L0.75,3 M0,3 L1,3 " <ColumnDefinition MaxWidth="20" MinWidth="5" />
Stretch="Fill" /> <ColumnDefinition Width="5" />
</Grid> </Grid.ColumnDefinitions>
</ControlTemplate> <Path Grid.Column="0" Stroke="#AC0000" StrokeThickness="1" Data="M0,0 L0,1 M0,0.75 L1,0.75" Stretch="Fill" SnapsToDevicePixels="True" />
</Setter.Value> <TextBlock Text="{Binding Path=ActualWidth, Converter={x:Static Converters:FormatDoubleConverter.Instance}}" HorizontalAlignment="Center" Margin="0,8,0,0" Padding="1,1,1,1" FontSize="10" Grid.Column="1" />
<Path Grid.Column="2" Stroke="#AC0000" StrokeThickness="1" Data="M0,0.75 L3,0.75 M3,0 L3,1 " Stretch="Fill" SnapsToDevicePixels="True" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:WidthDisplay}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:WidthDisplay}">
<Grid Height="22" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MaxWidth="20" MinWidth="5" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<Path Grid.Column="0"
Stroke="#AC0000"
StrokeThickness="1"
Data="M0,0 L0,1 M0,0.75 L1,0.75"
Stretch="Fill"
SnapsToDevicePixels="True"/>
<TextBlock Text="{Binding Path=ActualWidth, Converter={x:Static Converters:FormatDoubleConverter.Instance}}"
HorizontalAlignment="Center"
Margin="0,8,0,0"
Padding="1,1,1,1"
FontSize="10"
Grid.Column="1"/>
<Path Grid.Column="2"
Stroke="#AC0000"
StrokeThickness="1"
Data="M0,0.75 L3,0.75 M3,0 L3,1 "
Stretch="Fill"
SnapsToDevicePixels="True"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:InPlaceEditor}"> <Style TargetType="{x:Type Controls:InPlaceEditor}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:InPlaceEditor}"> <ControlTemplate TargetType="{x:Type Controls:InPlaceEditor}">
<TextBox Name="editor" <TextBox Name="editor" ToolTip="Edit the Text. Press ESC key to make changes." SnapsToDevicePixels="True" Padding="{Binding Path=Padding}" FontSize="{Binding Path=FontSize}" FontFamily="{Binding Path=FontFamily}" FontStyle="{Binding Path=FontStyle}" FontStretch="{Binding Path=FontStretch}" FontWeight="{Binding Path=FontWight}" Text="{Binding Path=Bind, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" />
ToolTip="Edit the Text. Press ESC key to make changes."
SnapsToDevicePixels="True"
Padding="{Binding Path=Padding}"
FontSize="{Binding Path=FontSize}"
FontFamily="{Binding Path=FontFamily}"
FontStyle="{Binding Path=FontStyle}"
FontStretch="{Binding Path=FontStretch}"
FontWeight="{Binding Path=FontWight}"
Text="{Binding Path=Bind, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
AcceptsReturn="True"
MaxHeight="{Binding Path=Height, UpdateSourceTrigger=PropertyChanged}"
MaxWidth="{Binding Path=Width, UpdateSourceTrigger=PropertyChanged}"/>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
<Style TargetType="{x:Type Controls:QuickOperationMenu}"> <Style TargetType="{x:Type Controls:QuickOperationMenu}">
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:QuickOperationMenu}"> <ControlTemplate TargetType="{x:Type Controls:QuickOperationMenu}">
<Menu Height="15" HorizontalAlignment="Left" Name="menu1" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent"> <Menu Height="15" HorizontalAlignment="Left" Name="menu1" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent">
<MenuItem Height="15" Width="15" Padding="0" Background="Transparent" BorderThickness="1" Name="MainHeader"> <MenuItem Height="15" Width="15" Padding="0" Background="Transparent" BorderThickness="1" Name="MainHeader">
<MenuItem.Header> <MenuItem.Header>
<Path Data="M3.5,5.5 L11.5,5.5 L7.5,11 z" Fill="Black" Stroke="Gray" StrokeThickness="1" /> <Path Data="M3.5,5.5 L11.5,5.5 L7.5,11 z" Fill="Black" Stroke="Gray" StrokeThickness="1" />
</MenuItem.Header> </MenuItem.Header>
</MenuItem> </MenuItem>
</Menu> </Menu>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>

138
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/InPlaceEditor.cs

@ -17,7 +17,7 @@ using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Controls namespace ICSharpCode.WpfDesign.Designer.Controls
{ {
/// <summary> /// <summary>
/// Supports editing Text in the Designer /// Supports editing Text in the Designer
/// </summary> /// </summary>
public class InPlaceEditor : TextBox public class InPlaceEditor : TextBox
{ {
@ -27,21 +27,23 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
} }
/// <summary> /// <summary>
/// This property is binded to the Text Property of the editor. /// This property is binded to the Text Property of the editor.
/// </summary> /// </summary>
public static readonly DependencyProperty BindProperty = public static readonly DependencyProperty BindProperty =
DependencyProperty.Register("Bind", typeof (string), typeof (InPlaceEditor), new FrameworkPropertyMetadata()); DependencyProperty.Register("Bind", typeof (string), typeof (InPlaceEditor), new FrameworkPropertyMetadata());
public string Bind{ public string Bind{
get { return (string) GetValue(BindProperty); } get { return (string) GetValue(BindProperty); }
set { SetValue(BindProperty, value); } set { SetValue(BindProperty, value); }
} }
readonly DesignItem designItem; readonly DesignItem designItem;
ChangeGroup changeGroup; ChangeGroup changeGroup;
TextBlock textBlock; TextBlock textBlock;
TextBox editor; TextBox editor;
bool _isChangeGroupOpen;
/// <summary> /// <summary>
/// This is the name of the property that is being edited for example Window.Title, Button.Content . /// This is the name of the property that is being edited for example Window.Title, Button.Content .
/// </summary> /// </summary>
@ -53,12 +55,12 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
} }
public override void OnApplyTemplate() public override void OnApplyTemplate()
{ {
base.OnApplyTemplate(); base.OnApplyTemplate();
editor = new TextBox(); editor = new TextBox();
editor = Template.FindName("editor", this) as TextBox; // Gets the TextBox-editor from the Template editor = Template.FindName("editor", this) as TextBox; // Gets the TextBox-editor from the Template
Debug.Assert(editor != null); Debug.Assert(editor != null);
} }
/// <summary> /// <summary>
/// Binds the Text Property of the element extended with <see cref="Bind"/>. /// Binds the Text Property of the element extended with <see cref="Bind"/>.
@ -68,66 +70,94 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{ {
Debug.Assert(textBlock!=null); Debug.Assert(textBlock!=null);
this.textBlock = textBlock; this.textBlock = textBlock;
Binding binding = new Binding("Text"); Binding binding = new Binding("Text");
binding.Source = this.textBlock; binding.Source = this.textBlock;
binding.Mode = BindingMode.TwoWay; binding.Mode = BindingMode.TwoWay;
SetBinding(BindProperty, binding); SetBinding(BindProperty, binding);
property=PropertyUpdated(textBlock); property=PropertyUpdated(textBlock);
} }
/// <summary> /// <summary>
/// Returns the property that is being edited in the element for example editing Window Title returns "Title", /// Returns the property that is being edited in the element for example editing Window Title returns "Title",
/// Button text as "Content". /// Button text as "Content".
/// </summary> /// </summary>
private string PropertyUpdated(TextBlock text) private string PropertyUpdated(TextBlock text)
{ {
MarkupObject obj = MarkupWriter.GetMarkupObjectFor(designItem.Component); MarkupObject obj = MarkupWriter.GetMarkupObjectFor(designItem.Component);
foreach (MarkupProperty property in obj.Properties) { foreach (MarkupProperty property in obj.Properties) {
if (property.DependencyProperty != null && property.StringValue == textBlock.Text) if (property.DependencyProperty != null && property.StringValue == textBlock.Text)
return property.Name; return property.Name;
} }
return null; return null;
} }
protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e) protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
{ {
base.OnGotKeyboardFocus(e); base.OnGotKeyboardFocus(e);
changeGroup = designItem.OpenGroup("Change Text"); StartEditing();
editor.Focus(); }
}
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e) protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{ {
if (changeGroup != null) if (changeGroup != null && _isChangeGroupOpen){
changeGroup.Abort(); changeGroup.Abort();
if (textBlock != null) _isChangeGroupOpen=false;
textBlock.Visibility = Visibility.Visible; }
base.OnLostKeyboardFocus(e); if (textBlock != null)
} textBlock.Visibility = Visibility.Visible;
base.OnLostKeyboardFocus(e);
}
/// <summary> /// <summary>
/// Change is committed if the user releases the Escape Key. /// Change is committed if the user releases the Escape Key.
/// </summary> /// </summary>
/// <param name="e"></param> /// <param name="e"></param>
protected override void OnKeyUp(KeyEventArgs e) protected override void OnKeyUp(KeyEventArgs e)
{ {
base.OnKeyUp(e); base.OnKeyUp(e);
if (e.Key == Key.Escape) { if (e.Key == Key.Escape) {
// Commit the changes to the DOM // Commit the changes to the DOM
if(property!=null) if(property!=null)
designItem.Properties[property].SetValue(Bind); designItem.Properties[property].SetValue(Bind);
designItem.Properties[Control.FontFamilyProperty].SetValue(editor.FontFamily); if(designItem.Properties[Control.FontFamilyProperty].ValueOnInstance!=editor.FontFamily)
designItem.Properties[Control.FontSizeProperty].SetValue(editor.FontSize); designItem.Properties[Control.FontFamilyProperty].SetValue(editor.FontFamily);
designItem.Properties[Control.FontStretchProperty].SetValue(editor.FontStretch); if((double)designItem.Properties[Control.FontSizeProperty].ValueOnInstance!=editor.FontSize)
designItem.Properties[Control.FontStyleProperty].SetValue(editor.FontStyle); designItem.Properties[Control.FontSizeProperty].SetValue(editor.FontSize);
designItem.Properties[Control.FontWeightProperty].SetValue(editor.FontWeight); if((FontStretch)designItem.Properties[Control.FontStretchProperty].ValueOnInstance!=editor.FontStretch)
designItem.Properties[Control.FontStretchProperty].SetValue(editor.FontStretch);
if (changeGroup != null) if((FontStyle)designItem.Properties[Control.FontStyleProperty].ValueOnInstance!=editor.FontStyle)
changeGroup.Commit(); designItem.Properties[Control.FontStyleProperty].SetValue(editor.FontStyle);
changeGroup = null; if((FontWeight)designItem.Properties[Control.FontWeightProperty].ValueOnInstance!=editor.FontWeight)
this.Visibility = Visibility.Hidden; designItem.Properties[Control.FontWeightProperty].SetValue(editor.FontWeight);
textBlock.Visibility = Visibility.Visible;
} if (changeGroup != null && _isChangeGroupOpen){
} changeGroup.Commit();
_isChangeGroupOpen=false;
}
changeGroup = null;
this.Visibility = Visibility.Hidden;
textBlock.Visibility = Visibility.Visible;
}
}
public void AbortEditing()
{
if(changeGroup!=null && _isChangeGroupOpen){
changeGroup.Abort();
_isChangeGroupOpen=false;
}
this.Visibility= Visibility.Hidden;
textBlock.Visibility=Visibility.Visible;
}
public void StartEditing()
{
if(changeGroup==null){
changeGroup = designItem.OpenGroup("Change Text");
_isChangeGroupOpen=true;
}
this.Visibility=Visibility.Visible;
textBlock.Visibility=Visibility.Hidden;
}
} }
} }

91
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs

@ -10,6 +10,7 @@ using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Controls; using System.Windows.Controls;
@ -36,8 +37,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
bool isGettingDragged; // Flag to get/set whether the extended element is dragged. bool isGettingDragged; // Flag to get/set whether the extended element is dragged.
bool isMouseDown; // Flag to get/set whether left-button is down on the element. bool isMouseDown; // Flag to get/set whether left-button is down on the element.
int numClicks; // No of left-button clicks on the element. int numClicks; // No of left-button clicks on the element.
public InPlaceEditorExtension() public InPlaceEditorExtension()
{ {
adornerPanel=new AdornerPanel(); adornerPanel=new AdornerPanel();
isGettingDragged=false; isGettingDragged=false;
@ -77,10 +78,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
void PropertyChanged(object sender,PropertyChangedEventArgs e) void PropertyChanged(object sender,PropertyChangedEventArgs e)
{ {
if (textBlock != null) { if (textBlock != null) {
if (e.PropertyName == "Width") if (e.PropertyName == "Width"){
placement.XOffset = Mouse.GetPosition((IInputElement) element).X - Mouse.GetPosition(textBlock).X; placement.XOffset = Mouse.GetPosition((IInputElement) element).X - Mouse.GetPosition(textBlock).X-2.8;
if (e.PropertyName == "Height") editor.MaxWidth = Math.Max((ModelTools.GetWidth(element) - placement.XOffset), 0);
placement.YOffset = Mouse.GetPosition((IInputElement) element).Y - Mouse.GetPosition(textBlock).Y; }
if (e.PropertyName == "Height"){
placement.YOffset = Mouse.GetPosition((IInputElement) element).Y - Mouse.GetPosition(textBlock).Y-1;
editor.MaxHeight = Math.Max((ModelTools.GetHeight(element) - placement.YOffset), 0);
}
AdornerPanel.SetPlacement(editor, placement); AdornerPanel.SetPlacement(editor, placement);
} }
} }
@ -96,8 +101,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
Debug.Assert(textBlock!=null); Debug.Assert(textBlock!=null);
/* Gets the offset between the top-left corners of the element and the editor*/ /* Gets the offset between the top-left corners of the element and the editor*/
placement.XOffset = e.GetPosition(element).X - e.GetPosition(textBlock).X; placement.XOffset = e.GetPosition(element).X - e.GetPosition(textBlock).X -2.8;
placement.YOffset = e.GetPosition(element).Y - e.GetPosition(textBlock).Y; placement.YOffset = e.GetPosition(element).Y - e.GetPosition(textBlock).Y -1;
placement.XRelativeToAdornerWidth = 0; placement.XRelativeToAdornerWidth = 0;
placement.XRelativeToContentWidth = 0; placement.XRelativeToContentWidth = 0;
placement.YRelativeToAdornerHeight = 0; placement.YRelativeToAdornerHeight = 0;
@ -107,9 +112,33 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/* Change data context of the editor to the TextBlock */ /* Change data context of the editor to the TextBlock */
editor.DataContext=textBlock; editor.DataContext=textBlock;
/* Set MaxHeight and MaxWidth so that editor doesn't cross the boundaries of the control */
var height = ModelTools.GetHeight(element);
var width = ModelTools.GetWidth(element);
editor.MaxHeight = Math.Max((height - placement.YOffset), 0);
editor.MaxWidth = Math.Max((width - placement.XOffset), 0);
/* Hides the TextBlock in control because of some minor offset in placement, overlaping makes text look fuzzy */ /* Hides the TextBlock in control because of some minor offset in placement, overlaping makes text look fuzzy */
textBlock.Visibility = Visibility.Hidden; // textBlock.Visibility = Visibility.Hidden; //
AdornerPanel.SetPlacement(editor, placement); AdornerPanel.SetPlacement(editor, placement);
RemoveBorder(); // Remove the highlight border.
}
/// <summary>
/// Aborts the editing. This aborts the underlying change group of the editor
/// </summary>
public void AbortEdit()
{
editor.AbortEditing();
}
/// <summary>
/// Starts editing once again. This aborts the underlying change group of the editor
/// </summary>
public void StartEdit()
{
editor.StartEditing();
} }
#region MouseEvents #region MouseEvents
@ -142,6 +171,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
editor.Focus(); editor.Focus();
} }
} }
DrawBorder((FrameworkElement) result.VisualHit);
}else{
RemoveBorder();
} }
} }
@ -164,6 +196,47 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
#endregion #endregion
#region HighlightBorder
private Border _border;
private sealed class BorderPlacement : AdornerPlacement
{
private readonly FrameworkElement _element;
public BorderPlacement(FrameworkElement element)
{
_element = element;
}
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = _element.TranslatePoint(new Point(), panel.AdornedElement);
var rect = new Rect(p, _element.RenderSize);
rect.Inflate(3, 1);
adorner.Arrange(rect);
}
}
private void DrawBorder(FrameworkElement item)
{
if (editor != null && editor.Visibility != Visibility.Visible) {
if (adornerPanel.Children.Contains(_border))
adornerPanel.Children.Remove(_border);
_border = new Border {BorderBrush = Brushes.Gray, BorderThickness = new Thickness(1.4), ToolTip = "Edit this Text", SnapsToDevicePixels = true};
var shadow = new DropShadowEffect {Color = Colors.LightGray, ShadowDepth = 3};
_border.Effect = shadow;
var bp = new BorderPlacement(item);
AdornerPanel.SetPlacement(_border, bp);
adornerPanel.Children.Add(_border);
}
}
private void RemoveBorder()
{
if (adornerPanel.Children.Contains(_border))
adornerPanel.Children.Remove(_border);
}
#endregion
protected override void OnRemove() protected override void OnRemove()
{ {
ExtendedItem.PropertyChanged -= PropertyChanged; ExtendedItem.PropertyChanged -= PropertyChanged;

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs

@ -106,9 +106,17 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
} }
Size oldSize; Size oldSize;
// TODO : Remove all hide/show extensions from here.
void drag_Started(DragListener drag) void drag_Started(DragListener drag)
{ {
/* Abort editing Text if it was editing, because it interferes with the undo stack. */
foreach(var extension in this.ExtendedItem.Extensions){
if(extension is InPlaceEditorExtension){
((InPlaceEditorExtension)extension).AbortEdit();
}
}
oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View)); oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
if (resizeBehavior != null) if (resizeBehavior != null)
operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize); operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
@ -163,7 +171,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (drag.IsCanceled) changeGroup.Abort(); if (drag.IsCanceled) changeGroup.Abort();
else changeGroup.Commit(); else changeGroup.Commit();
changeGroup = null; changeGroup = null;
} }
_isResizing=false; _isResizing=false;
HideSizeAndShowHandles(); HideSizeAndShowHandles();
} }
@ -207,6 +215,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
r.Visibility = isVisible ? Visibility.Visible : Visibility.Hidden; r.Visibility = isVisible ? Visibility.Visible : Visibility.Hidden;
} }
} }
void ShowSizeAndHideHandles() void ShowSizeAndHideHandles()
{ {
SizeDisplayExtension sizeDisplay=null; SizeDisplayExtension sizeDisplay=null;

Loading…
Cancel
Save