I have a border in my WPF-Application and I want to have some text inside of my border like in my picture below.
But I could not figure out how to do it.
My code right now:
<Border Margin="10" BorderThickness="5px" BorderBrush="Gray" CornerRadius="5" Grid.Column="0" Grid.Row="1">
<RadioButton Margin="5">Test</RadioButton>
</Border>
Thanks for your help!
You could use a GroupBox that meets your needs.
<Grid>
<GroupBox Margin="10">
<GroupBox.Header>
Some Text
</GroupBox.Header>
<TextBlock TextWrapping="WrapWithOverflow" Margin="10" Text="Happy every day!"/>
</GroupBox>
</Grid>
i have a slight problem with the grid layout manager in WPF, using DotNetCore 3.1. I have the following code:
<TabControl Grid.Row="4" Grid.Column="0" Margin="0,0,5,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Top">
<TabItem Header="APM ops">
<UniformGrid Rows="6" Columns="1" Margin="5,5,5,5" HorizontalAlignment="Center" VerticalAlignment="Top">
<GroupBox Name="CheckStatus" Header="Check status" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<UniformGrid Grid.Row="0" Rows="1" Columns="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button HorizontalAlignment="Left" VerticalAlignment="Center">HAC processes</Button>
<Button HorizontalAlignment="Right" VerticalAlignment="Center">Nanny processes</Button>
</UniformGrid>
</GroupBox>
<GroupBox Name="RestartProcesses" Header="Restart services" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<UniformGrid Rows="8" Columns="2" HorizontalAlignment="Center" VerticalAlignment="Top">
<CheckBox>hornetq</CheckBox>
<CheckBox>marble_supervisor</CheckBox>
<CheckBox>odb</CheckBox>
<CheckBox>offline_engine</CheckBox>
<CheckBox>mercuryAS</CheckBox>
<CheckBox>businessImpactService</CheckBox>
<CheckBox>pmanager</CheckBox>
<CheckBox>db_loader</CheckBox>
<CheckBox>marble_loader</CheckBox>
<CheckBox>schedulergw</CheckBox>
<CheckBox>marble_worker</CheckBox>
<CheckBox>wde</CheckBox>
<CheckBox>marble_matcher</CheckBox>
<RadioButton>(make a selection)</RadioButton>
<Button>Restart</Button>
<RadioButton>(make a selection)</RadioButton>
</UniformGrid>
</GroupBox>
</UniformGrid>
</TabItem>
<TabItem Header="Java VM ops"/>
<TabItem Header="Server cfg"/>
<TabItem Header="Credential cfg"/>
</TabControl>
what I get is this:
What I would like to get is something more like this, where the gap betwenn the two GroupBoxes is minimized and there is some sort of margin between the checkboxes of the second Groupbox:
However, I don't seem to be able to find the correct controls and/or properties. Thanks in advance!
I figured it out. I needed to use the Grid property, not the UniformGrid ("duh!")... I guess in retrospect, it was kind of obvious, but I apparently couldn't see the forest for the trees.
I`ve created big button which contains grid as below:
<Button Height="Auto" Width="Auto" Command="{Binding ContinueWithoutScan}" BorderThickness="0">
<Button.Template>
<ControlTemplate>
<Grid >
<TextBlock HorizontalAlignment="Center"
TextWrapping="Wrap" Text="Text"
VerticalAlignment="Center" FontWeight="DemiBold"
Height="Auto" Width="Auto"
FontSize="25" Foreground="White"/>
<materialDesign:PackIcon Height="Auto" Width="70" Kind="ChevronRight" Foreground="White"
VerticalAlignment="Center" HorizontalAlignment="Right"/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
There is problem that only TextBlock inside Template is clickable. Does anyone know how do I make whole content clickable? I working with MVVM so I dont want make Grid.OnMouseEneter.
Is there option to do that of I have to use EventTriggers?
The Grid needs to have a Background other than the default null to receive input events. You may set a transparent background instead of null:
<Grid Background="Transparent">
...
</Grid>
Below is the code scenario.
<controls:TabControl x:Name="TC" Background="Black" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,8" Style="{StaticResource TabControlStyle1}" HorizontalAlignment="Left" VerticalAlignment="Center" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Padding="2">
<controls:TabItem Header="TAB1" x:Name="Tab1" Style="{StaticResource TabItemStyle2}" Foreground="#FFFDFDFD">
<Grid>
<local:UC1 x:Name="childUc1" Width="Auto" Height="Auto"/>
</Grid>
</controls:TabItem>
<controls:TabItem Header="TAB2" x:Name="Tab2" Style="{StaticResource TabItemStyle2}" Foreground="White">
<Grid>
<local:UC2 Margin="0" Width="Auto" HorizontalContentAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Grid>
</controls:TabItem>
</controls:TabControl>
Here from the second tab there is one control and from that control there is one button when user click on that button then that would change to first tab. How this possible?
Please anybody help on this issue then that would be a good.
Thanks,
I assume you are always going to have two tabs,On the click event of usercontrol, you can do like this,
TC.SelectedIndex = 0;
I am trying to modify my simple control so that the text box does not grow as the user types in long text. I took a look at some solutions posted here at Stackoverflow that suggest using a Grid and an invisible Border and binding the Width of the text box to the ActualWidth of the Border, but I can't seem to get it to work in my setup.
Here is the xaml of my control:
<StackPanel Margin="5,0">
<WrapPanel Margin="0,0,0,5">
<TextBlock Foreground="White" Margin="0,0,2,0">TEXT</TextBlock>
<TextBlock Foreground="#FF0099CC" FontWeight="Bold">MORE TEXT</TextBlock>
</WrapPanel>
<Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
<StackPanel Orientation="Horizontal">
<Image Source="..\Resources\zoom.png" Width="13"/>
<TextBox Foreground="White" Background="Black" BorderBrush="Transparent">THIS IS SOME TEXT</TextBox>
</StackPanel>
</Border>
</StackPanel>
Any ideas? I need the zoom.png to appear "inside" of the text box so I use a horizontal stack panel and just place the image and text box side by side, both surrounded by the same border.
Is there a way for me to stop my text box from auto growing as text is typed?
Thanks.
UPDATE:
Below is the xaml I am testing with.
<Window x:Class="Desktop.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:composite="http://www.codeplex.com/CompositeWPF"
Title="MyShell" Height="50" Width="900"
WindowStyle="None"
ShowInTaskbar="False"
AllowsTransparency="True"
Background="Transparent"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterScreen">
<Border BorderBrush="Black"
BorderThickness="1.5"
CornerRadius="5"
Background="Gray">
<ItemsControl composite:RegionManager.RegionName="MainRegion">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Border>
</Window>
<UserControl x:Class="Desktop.SearchTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="50" Margin="0">
<StackPanel Margin="5,0">
<WrapPanel Margin="0,0,0,5">
<TextBlock Foreground="White" Margin="0,0,2,0">TEXT</TextBlock>
<TextBlock Foreground="#FF0099CC" FontWeight="Bold">MORE TEXT</TextBlock>
</WrapPanel>
<Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
<Grid x:Name="grdTest">
<Image HorizontalAlignment="Left" Source="..\Resources\zoom.png" Width="13"/>
<TextBox Margin="16,0,0,0" Foreground="White" Background="Black" BorderBrush="Transparent" Width="{Binding ElementName=grdTest, Path=ActualWidth}">THIS IS SOME TEXT</TextBox>
</Grid>
</Border>
</StackPanel>
</UserControl>
I just add my user control to the Window's MainRegion.
I did some more searching and found the solution. I used the below Grid to replace the grid in my original post and now the text box keeps its original size and does not auto grow on long user input. Thanks to all who looked into this.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Source="..\Resources\zoom.png" Width="13"/>
<Border x:Name="b" Grid.Column="1"/>
<TextBox Width="{Binding ActualWidth, ElementName=b}" Foreground="White" Background="Black" BorderBrush="Transparent"
Grid.Column="1"
VerticalAlignment="Center"
Text="THIS IS SOME TEXT"/>
</Grid>
Try to put ScrollViewer.HorizontalScrollBarVisibility="Disabled" inside Grid.
Name the Grid as x:Name="grdTest" and try this
<Grid x:Name="grdTest">
<Image HorizontalAlignment="Left" Source="..\Resources\zoom.png" Width="13"/>
<TextBox Margin="16,0,0,0" Foreground="White" Background="Black" BorderBrush="Transparent"
Width="{Binding ElementName=grdTest, Path=ActualWidth}">THIS IS SOME TEXT</TextBox>
</Grid>
To stop the grow behavior set an explicit size to the TextBox or place it in a grid with the HorizontalAlignment set to stretch
Option 1:
<TextBox Width="60">THIS IS SOME TEXT</TextBox>
Option 2:
<TextBox HorizontalAlignment="Stretch">THIS IS SOME TEXT</TextBox>
I had a very similar issue, and it turned out that my Window property "SizeToContent" was set to "WidthAndHeight", I removed setting that property, (which then defaults to "Manual") and this fixed my similar issue.
To scale the border containing the textbox to the width of the outter stack panel, change the inner stack panel to a grid and set a left margin on the text box so it doesn't overlap with the image. Also set the image's horizontal alignment to left (if that is where you want it) or it will default to the center of the border.
<StackPanel Margin="5,0">
<WrapPanel Margin="0,0,0,5">
<TextBlock Foreground="White" Margin="0,0,2,0">TEXT</TextBlock>
<TextBlock Foreground="#FF0099CC" FontWeight="Bold">MORE TEXT</TextBlock>
</WrapPanel>
<Border Margin="2,4,0,4" BorderThickness="1" SnapsToDevicePixels="True" Background="Black"
BorderBrush="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
<Grid>
<Image HorizontalAlignment="Left" Source="..\Resources\zoom.png" Width="13"/>
<TextBox Margin="16,0,0,0" Foreground="White" Background="Black" BorderBrush="Transparent">THIS IS SOME TEXT</TextBox>
</Grid>
</Border>
</StackPanel>
This article shows a solution for a textbox that is displayed inside a scrollviewer's viewport (in treeview or listbox). A PART_MeasureTextBlock is used (bound to the textbox) to determine the available size and set it to the textbox.
Please have look here and tell me what you think about it:
http://www.codeproject.com/Articles/802385/A-WPF-MVVM-In-Place-Edit-TextBox-Control