Please see this image for what I'm referring to as a static box:
I'm not sure if that is it's proper name.
The box should be able to hold an arbitrary child control (panel etc.) inside.
In WPF, it is called a GroupBox
See the MSDN documentation for the control:
http://msdn.microsoft.com/en-us/library/system.windows.controls.groupbox.aspx
How to use it
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<GroupBox Header="Test 1">
<StackPanel Margin="6">
<RadioButton x:Name="option1RadioButton" Content="Option 1" />
<RadioButton x:Name="option2RadioButton" Content="Option 2" />
<RadioButton x:Name="option3RadioButton" Content="Option 3" />
</StackPanel>
</GroupBox>
</Window>
Cool features
The WPF GroupBox is a bit more powerful than your standard Win32 group box. Instead of just being able to set text in the header, you can set any sort of content you want, such as images, or other controls:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<GroupBox>
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Button Content="Test 1" />
<Label Content="Test 2" />
<Button Content="Test 3" />
</StackPanel>
</GroupBox.Header>
<StackPanel Margin="6">
<RadioButton x:Name="option1RadioButton" Content="Option 1" />
<RadioButton x:Name="option2RadioButton" Content="Option 2" />
<RadioButton x:Name="option3RadioButton" Content="Option 3" />
</StackPanel>
</GroupBox>
</Window>
Yep, that's called a GroupBox in WinForms/WPF world.
To set the text in it, set the Header property:
<GroupBox Header="Some Text">
<Grid>
<!--Other Controls-->
</Grid>
</GroupBox>
Related
Hi i have the following window, it has a button, and when i click on it, it shows a popup that contains some text. When the popup is closed, the behaviour cleans the text inside the popup
<Window
x:Class="WpfTests.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:behaviours="http://schemas.microsoft.com/xaml/behaviors"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfTests"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="300"
Height="300"
mc:Ignorable="d">
<StackPanel
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Red"
Orientation="Vertical">
<ToggleButton
x:Name="CustomButton"
Width="40"
Height="40"
Content="Checkbutton" />
<Popup
IsOpen="{Binding ElementName=CustomButton, Path=IsChecked}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=CustomButton}"
StaysOpen="False">
<behaviours:Interaction.Triggers>
<behaviours:EventTrigger EventName="Closed">
<behaviours:ChangePropertyAction
PropertyName="Text"
TargetObject="{Binding ElementName=UrlTextBox}"
Value="" />
</behaviours:EventTrigger>
</behaviours:Interaction.Triggers>
<TextBlock
x:Name="UrlTextBox"
Width="100"
Height="100"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Green"
Foreground="White"
Text="A url" />
</Popup>
</StackPanel>
Now, if i change the child of the popup to a user control like the following:
<Popup
IsOpen="{Binding ElementName=CustomButton, Path=IsChecked}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=CustomButton}"
StaysOpen="False">
<behaviours:Interaction.Triggers>
<behaviours:EventTrigger EventName="Closed">
<behaviours:ChangePropertyAction
PropertyName="Text"
TargetObject="{Binding ElementName=CustomControl, Path=UrlTextBox}"
Value="" />
</behaviours:EventTrigger>
</behaviours:Interaction.Triggers>
<local:CustomControl x:Name="CustomControl" />
</Popup>
CustomControl:
<UserControl
x:Class="WpfTests.CustomControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfTests"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<TextBlock
x:Name="UrlTextBox"
Width="100"
Height="100"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Green"
Foreground="White"
Text="A url" />
The behaviour crashes, because it cannot find the property text and i don't know why.
I know i can do this using code behind, but i would like to do it in the xaml.
Any help would be appreciated
This line isn't going to work
TargetObject="{Binding ElementName=CustomControl, Path=UrlTextBox}"
Because the Path part needs to point to a Property (the TextBlock inside the UserControl is compiled as a public field).
You need to add a line in you UserControl code-behind like this:
public TextBlock UrlText => this.UrlTextBox;
and then in your behaviour change it to this
TargetObject="{Binding ElementName=CustomControl, Path=UrlText}"
I have a SplitButton in my WPF window, which is borrowed from Xceed's Extended WPF Toolkit. Its dropdown content is consisted of some RadioButtons. Something like:
<Window x:Class="WpfTest.Test3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
Title="Test3" Height="300" Width="300">
<Grid Height="25" Width="150">
<tk:SplitButton Content="Default Command">
<tk:SplitButton.DropDownContent>
<StackPanel>
<RadioButton Content="Default Command" GroupName="variations" Margin="5" IsChecked="True"/>
<RadioButton Content="Alternate Command 1" GroupName="variations" Margin="5"/>
<RadioButton Content="Alternate Command 2" GroupName="variations" Margin="5"/>
</StackPanel>
</tk:SplitButton.DropDownContent>
</tk:SplitButton>
</Grid>
</Window>
which generates something like this:
The problem is, when I click on each of the RadioButtons the dropdown menu doesn't dissappear. I did some googling and realized that I should handle the Click event for each RadioButton. But I don't know how to hide the dropdown menu in that event handler. As a side-note, it seems a MenuItem has the property of StaysOpenOnClick, but there is no such thing for other controls.
Although doing this programmatically would suffice, but is there an MVVM way for this?
Add Checked event on your radio button and use SplitoButton.IsOpen=false;. Follow this code.
Xaml
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
Title="MainWindow" Height="350" Width="525">
<Grid>
<tk:SplitButton Name="SplitButton" Content="Default Command">
<tk:SplitButton.DropDownContent>
<StackPanel>
<RadioButton Checked="rb_Checked" Content="Default Command" GroupName="variations" Margin="5" IsChecked="True"/>
<RadioButton Checked="rb_Checked" Content="Alternate Command 1" GroupName="variations" Margin="5"/>
<RadioButton Checked="rb_Checked" Content="Alternate Command 2" GroupName="variations" Margin="5"/>
</StackPanel>
</tk:SplitButton.DropDownContent>
</tk:SplitButton>
</Grid>
</Window>
.cs
private void rb_Checked(object sender, RoutedEventArgs e)
{
SplitButton.IsOpen = false;
}
Here's a picture of the overlay from the sample app:
Here's the git page of the Material Design In XAML Toolkit (you can download the demo project here): Toolkit:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit
This is probably property somewhere in the Material Design In XAML Toolkit library and i am asking if anyone knows how to set it (or if the overlay can even be turned off).
<Window x:Class="MaterialDesignColors.WpfExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfExample="clr-namespace:MaterialDesignColors.WpfExample"
xmlns:domain="clr-namespace:MaterialDesignColors.WpfExample.Domain"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:domain1="clr-namespace:MaterialDesignDemo.Domain"
xmlns:materialDesignDemo="clr-namespace:MaterialDesignDemo"
Title="Material Design in XAML" Height="800" Width="1100"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{StaticResource MaterialDesignFont}" Icon="favicon.ico">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- data template used for the dialogs example, defines a View for a ViewModel of type DateTime -->
<DataTemplate DataType="{x:Type system:DateTime}">
<StackPanel Margin="16">
<TextBlock>England win the World Cup:</TextBlock>
<TextBlock Margin="0 8 0 0" Text="{Binding }" />
<TextBlock Margin="0 8 0 0" >You will never see that again.</TextBlock>
<Button Margin="0 8 0 0" IsDefault="True" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Style="{DynamicResource MaterialDesignFlatButton}">AWESOME</Button>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</Window.Resources>
<materialDesign:DialogHost Identifier="RootDialog">
<materialDesign:DrawerHost IsLeftDrawerOpen="{Binding ElementName=MenuToggleButton, Path=IsChecked}">
<materialDesign:DrawerHost.LeftDrawerContent>
<DockPanel MinWidth="212">
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}"
DockPanel.Dock="Top"
HorizontalAlignment="Right" Margin="16"
IsChecked="{Binding ElementName=MenuToggleButton, Path=IsChecked, Mode=TwoWay}" />
<ListBox x:Name="DemoItemsListBox" Margin="0 16 0 16" SelectedIndex="0"
PreviewMouseLeftButtonUp="UIElement_OnPreviewMouseLeftButtonUp">
<ListBox.ItemTemplate>
<DataTemplate DataType="domain:DemoItem">
<TextBlock Text="{Binding Name}" Margin="32 0 32 0" />
</DataTemplate>
</ListBox.ItemTemplate>
<domain:DemoItem Name="Home">
...
<domain:DemoItem Name="Shadows">
<domain:DemoItem.Content>
<wpfExample:Shadows />
</domain:DemoItem.Content>
</domain:DemoItem>
</ListBox>
</DockPanel>
</materialDesign:DrawerHost.LeftDrawerContent>
<DockPanel>
<materialDesign:ColorZone Padding="16" materialDesign:ShadowAssist.ShadowDepth="Depth2"
Mode="PrimaryMid" DockPanel.Dock="Top">
<DockPanel>
<ToggleButton Style="{StaticResource MaterialDesignHamburgerToggleButton}" IsChecked="False"
x:Name="MenuToggleButton"/>
<materialDesign:PopupBox DockPanel.Dock="Right" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
<StackPanel>
<Button Content="Hello World" Click="MenuPopupButton_OnClick"/>
<Button Content="Nice Popup" Click="MenuPopupButton_OnClick"/>
<Button Content="Goodbye" Click="MenuPopupButton_OnClick"/>
</StackPanel>
</materialDesign:PopupBox>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22">Material Design In XAML Toolkit</TextBlock>
</DockPanel>
</materialDesign:ColorZone>
<ContentControl Margin="16" Content="{Binding ElementName=DemoItemsListBox, Path=SelectedItem.Content}" />
</DockPanel>
</materialDesign:DrawerHost>
</materialDesign:DialogHost>
</Window>
The black shade is due to a grid defined in Generic.xaml:
<Grid x:Name="PART_ContentCover" Background="{x:Null}" Opacity="0"
IsHitTestVisible="False" Focusable="False" />
Which is animated to set the opacity to 0.56 when the drawer is drawn. Unfortunatelly this grid does not belong to any template so you cannot change it in client xaml.
The other option is to change the shade's black brush which is also defined in Generic.xaml:
<SolidColorBrush x:Key="BlackBackground" Color="Black" />
But this is also something I wouldn't know how to change from a client xaml, so the only advice until someone with more WPF skillz gives a better option is to simply recompile the source and change the black brush to:
<SolidColorBrush x:Key="BlackBackground" Color="#00000000" />
Alternatively you can use the flyout control which is shown in the other demo that does not have the dark shade feature but other than that is the same.
Update: I've found one way to solve this. You can subclass DrawerHost like this:
public class DrawerHostEx : DrawerHost
{
public DrawerHostEx()
{
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var grid = GetTemplateChild(TemplateContentCoverPartName) as System.Windows.Controls.Grid;
grid.Visibility = System.Windows.Visibility.Collapsed;
}
}
Then you simply replace DrawerHost with DrawerHostEx in the XAML.
So, I am new to WPF. Actually, this is my first WPF project. I come from a unix desktop (and Web) programming background, so I'm not new to programming or mark up languages.
Q1: First, My application is a simple dialog that cannot be min/maximized or resized (for simplicity), so I don't mind fixing (ie. hardcoding) my layout.
Using HTML to explain, this is what I want my "form" to look like:
<div>
<div>
<span>This is my Left Adjusted Title</span>
<span>Some Right Adjusted Stuff</span>
</div>
<div>
<div>
<div>This is the parent container</div>
<div>
<div>Title for option 1</div>
<div>
Radio Button for option 1
</div>
<div>Title for option 2</div>
<div>
Radio Buttons for option 2
</div>
</div>
</div>
<div>
<span>Right Floated Button</span>
</div>
<hr />
<div>
<div>These are the Results</div>
<textarea>
Vertically scrollable text here (nice if can be color formatted with underlines etc) ...
</textarea>
</div>
<div id="footer">
<div><a href='http://www.google.com'>Click here</a></div>
</div>
</div>
</div>
This, on the other hand, is my XAML (which I have kludged together from the Visual Designer):
<Window x:Name="wndMain" x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ews="clr-namespace:ExtraWindowStyles"
ResizeMode="NoResize"
ews:ExtraWindowStyles.CanMinimize="false"
ews:ExtraWindowStyles.CanMaximize="false"
Title="Hello World" Height="501.492" Width="842.285">
<Grid>
<GroupBox Header="Input Parameters" HorizontalAlignment="Left" Height="173" Margin="10,25,0,0" VerticalAlignment="Top" Width="801" >
<StackPanel Orientation="Horizontal" Margin="0,0,96,0">
<StackPanel Margin="10">
<Label FontWeight="Bold">First Group</Label>
<RadioButton x:Name="opt11">Option 1 - 1</RadioButton>
<RadioButton x:Name="opt12">Option 1 - 2</RadioButton>
<RadioButton x:Name="opt13">Option 1 - 3</RadioButton>
</StackPanel>
<StackPanel Margin="10">
<Label FontWeight="Bold" Content="Second Group"/>
<RadioButton x:Name="opt21" Content="Option 2 - 1"/>
<RadioButton x:Name="opt22" Content="Option 2 - 2"/>
<RadioButton x:Name="opt23" Content="Option 2 - 3"/>
</StackPanel>
</StackPanel>
</GroupBox>
<Separator HorizontalAlignment="Left" Height="80" Margin="17,203,0,0" VerticalAlignment="Top" Width="794"/>
<Button x:Name="btnSubmit" Content="Explore" HorizontalAlignment="Left" Height="34" Margin="632,203,0,0" VerticalAlignment="Top" Width="179" Click="btnSubmit_Click" />
<Label Content="Results:" HorizontalAlignment="Left" Height="28" Margin="10,242,0,0" VerticalAlignment="Top" Width="161"/>
<Label Content="My App" HorizontalAlignment="Left" Height="23" Margin="696,439,0,0" VerticalAlignment="Top" Width="130" FontSize="9"/>
<TextBlock>
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate">
Click Here
</Hyperlink>
</TextBlock>
<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="162" Margin="17,270,0,0" Stroke="Black" VerticalAlignment="Top" Width="794"/>
<Label x:Name="lblResult" Content="" HorizontalAlignment="Left" Height="157" Margin="17,275,0,0" VerticalAlignment="Top" Width="794"/>
</Grid>
</Window>
How do I fix this XAML so it is rendered the way I showed in the HTML snippet?
Q2: Why does the WPF rendered button not behave like a button?. This is really wierd, it does not depress when clicked, how do I get the 'normal' button click behaviour ?
I've (mostly) updated your XAML, attached below, to get you started in the right direction. Of note, pay attention, as Bradley Uffner mentioned, to how elements are arranged within the Grid via RowDefinitions and the Grid.Row attached property.
Further, as you progress in WPF, look into MVVM pattern, as it creates much cleaner and more logic code, being much easier to maintain. To this end, you'll want to start familiarizing yourself on the Binding expressions in WPF, such as can be found at A Data Binding Primer.
I've left most of your static Height definitions in place, but you can also allow these controls to fit dynamically via any combination of Height on RowDefinition, Width on ColumnDefinition, and the HorizontalAlignment and VerticalAlignment of the controls themselves.
<Window x:Name="wndMain" x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfControlPositioning"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="Hello World" Height="501.492" Width="842.285"
WindowStyle="ToolWindow">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Header="Input Parameters" Height="173" Margin="10">
<StackPanel Orientation="Horizontal">
<StackPanel Margin="10">
<Label FontWeight="Bold">First Group</Label>
<RadioButton x:Name="opt11">Option 1 - 1</RadioButton>
<RadioButton x:Name="opt12">Option 1 - 2</RadioButton>
<RadioButton x:Name="opt13">Option 1 - 3</RadioButton>
</StackPanel>
<StackPanel Margin="10">
<Label FontWeight="Bold" Content="Second Group"/>
<RadioButton x:Name="opt21" Content="Option 2 - 1"/>
<RadioButton x:Name="opt22" Content="Option 2 - 2"/>
<RadioButton x:Name="opt23" Content="Option 2 - 3"/>
</StackPanel>
</StackPanel>
</GroupBox>
<Separator Grid.Row="1" Height="3" Margin="10,0"/>
<Button Grid.Row="2" x:Name="btnSubmit" Content="Explore" HorizontalAlignment="Right" Height="34" Margin="10" Width="179" Click="btnExplore_Click" />
<Label Grid.Row="3" Content="Results:" HorizontalAlignment="Left" Margin="10,0"/>
<!-- I don't know what to make of this, so I've left it commented out.
<TextBlock>
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate">
Click Here
</Hyperlink>
</TextBlock>
-->
<!-- Note that I've substituted a ReadOnly TextBox in place of the Rectangle + Label here. The TextBox supplies
the bordered look of the rectangle, but has the different behavior of allowing text selection from within
the control, such as for copying your Results to paste elsewhere. -->
<TextBox Grid.Row="4" x:Name="lblResult" Margin="10,0" IsReadOnly="True" Background="#FFF4F4F5" BorderBrush="Black"/>
<Label Grid.Row="5" Content="My App" HorizontalAlignment="Right" Height="23" Margin="0" FontSize="9"/>
</Grid>
</Window>
EDIT: I forgot to point out that, since you were arranging everything via Margin and had some odd sizes and layouts of some elements (i.e., the "Click Here" link) that the reason your Button didn't behave as expected is because it had other controls overlaying the top of it.
How to:
Disable resizing for this usercontrol. In other words, when the user grabs the corners or the sides of this usercontrol with a mouse, I dont want the user to be able to change the size of the usercontrol?
Or if there is no way to stop resizing then how do I only allow the right side of the usercontrol dragged?
<UserControl x:Class="MyEditor.MyDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="152" d:DesignWidth="590" HorizontalContentAlignment="Right" MinWidth="{Binding ElementName=VariableType}" MinHeight="{Binding RelativeSource={RelativeSource Self}}">
<Grid Width="591" Height="147" MinWidth="{Binding ElementName=VariableTypeTextBox}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="137*" />
<ColumnDefinition Width="454*" MinWidth="250" />
</Grid.ColumnDefinitions>
<Button Content="Cancel" Height="23" Margin="0,94,7,0" Name="CancelButton" VerticalAlignment="Top" Click="CancelButton_Click" Grid.Column="1" HorizontalAlignment="Right" Width="75" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" />
<Button Content="Create" Height="23" Margin="0,94,108,0" Name="CreateButton" VerticalAlignment="Top" Click="CreateButton_Click" Grid.Column="1" HorizontalAlignment="Right" Width="75" HorizontalContentAlignment="Center" VerticalContentAlignment="Top" />
<Label Content="Variable Name " Height="28" Margin="0,12,29,0" Name="VariableName" VerticalAlignment="Top" HorizontalAlignment="Right" Width="96" Target="{Binding}" HorizontalContentAlignment="Right" />
<TextBox Height="29" Margin="0,11,7,0" Name="VarNameTextBox" VerticalAlignment="Top" KeyDown="OnKeyDownHandler" MouseLeave="MouseLeaveHandler" LostFocus="LostFocusHandler" Grid.Column="1" HorizontalAlignment="Stretch" />
<Label Content="Variable Type" Height="28" Margin="0,0,29,73" Name="VariableType" VerticalAlignment="Bottom" HorizontalContentAlignment="Right" HorizontalAlignment="Right" Width="96" />
<TextBox Height="23" Margin="0,51,7,0" Name="VariableTypeTextBox" VerticalAlignment="Top" IsReadOnly="True" Background="Silver" Foreground="Black" Grid.Column="1" HorizontalAlignment="Stretch" Width="AUTO" />
</Grid>
You've pasted the XAML for a UserControl, but your question is asking about a Window. So, you will need to place your UserControl inside a Window that is set up to not allow resizing.
A WPF Window has a ResizeMode property, which can be one of the following:
NoResize
CanMinimize
CanResize (default)
CanResizeWithGrip
You will want NoResize.
Example:
<Window x:Class="MyEditor.Views.EditorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:views="clr-namespace:MyEditor"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="Editor Window">
<views:MyDialog />
</Window>
Please see the documentation for more details.
Simply set the MinWidth/MaxWidth and MinHeight/MaxHeight properties to your required value.
For Disabling : ResizeMode="CanMinimize"
<Window x:Class="XXXXXX.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:XXXXXXX"
mc:Ignorable="d"
WindowState="Maximized"
ResizeMode="CanMinimize"
Title="Window">
Here is a simple solution:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
((Window)Parent).ResizeMode = ResizeMode.NoResize;
}
Or an attached property on the UserControl if you use the Prism Library:
<prism:Dialog.WindowStyle>
<Style TargetType="Window">
<Setter Property="prism:Dialog.WindowStartupLocation"
Value="CenterScreen" />
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="ShowInTaskbar" Value="False"/>
Setter Property="SizeToContent" Value="WidthAndHeight"/>
</Style>
</prism:Dialog.WindowStyle>