There is a style for resizing a component in the Xaml markup:
<Window.Resources> <Style x:Key="{x:Type self:ResizablePanel}" TargetType="{x:Type self:ResizablePanel}"> <Setter Property="Template" > <Setter.Value> <ControlTemplate TargetType="{x:Type self:ResizablePanel}"> <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="5"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="5"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="5"/> <RowDefinition Height="*"/> <RowDefinition Height="5"/> </Grid.RowDefinitions> <self:Resizer Cursor="SizeNWSE" Background="Gray" Width="3" Height="3" Grid.Row="0" Grid.Column="0" ThumbDirection="TopLeft"/> <self:Resizer Cursor="SizeWE" Background="LightGray" Width="1" Grid.Row="1" Grid.Column="0" ThumbDirection="Left"/> <self:Resizer Cursor="SizeNESW" Background="Gray" Width="3" Height="3" Grid.Row="2" Grid.Column="0" ThumbDirection="BottomLeft" /> <self:Resizer Cursor="SizeNS" Background="LightGray" Height="1" Grid.Row="2" Grid.Column="1" ThumbDirection="Bottom" /> <self:Resizer Cursor="SizeNWSE" Background="Gray" Width="3" Height="3" Grid.Row="2" Grid.Column="2" ThumbDirection="BottomRight" /> <self:Resizer Cursor="SizeWE" Background="LightGray" Width="1" Grid.Row="1" Grid.Column="2" ThumbDirection="Right"/> <self:Resizer Cursor="SizeNESW" Background="Gray" Width="3" Height="3" Grid.Row="0" Grid.Column="2" ThumbDirection="TopRight"/> <self:Resizer Cursor="SizeNS" Background="LightGray" Height="1" Grid.Row="0" Grid.Column="1" ThumbDirection="Top"/> <ContentPresenter Grid.Row="1" Grid.Column="1" Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}"></ContentPresenter> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> Here is its application to the RichTextBox in the Xaml markup:
<self:ResizablePanel Grid.Column="0" Grid.Row="2" Height="300" Width="Auto" MinHeight="60" Margin="20, 30, 20, 20"> <RichTextBox x:Name="SomeName" </RichTextBox> </self:ResizablePanel> Resizable Panel defined in a separate class.
using System.Windows; using System.Windows.Controls; namespace TextEditorForDimploma { public class ResizablePanel : ContentControl { static ResizablePanel() { // This will allow us to create a Style in Generic.xaml with target type ResizablePanel. DefaultStyleKeyProperty.OverrideMetadata(typeof(ResizablePanel), new FrameworkPropertyMetadata(typeof(ResizablePanel))); } } } You must apply a style to the Image component in your code.
When using <... x:Key = "SomeKey"> and trying to find it in the codestyle = (Style)FindResource("SomeKey") as Style; does not display image at all.
style = (Style)FindResource("SomeKey") as Style; used in the event handler responsible for adding a picture.
ResizablePaneldefined? - VladDstyle = (Style)FindResource("SomeKey") as Style? Vanguey, that in the designer. - VladDFindResourcewill not reach the window, not like it. - VladD