How can i increase the spacing between radio buttons - c#

I can't find any way to increase the spacing between each radio button to match the format of my interface
this is my XAML code for the radio button
<dxe:ListBoxEdit Name="xrbSplitFreight" Grid.Row="1" Grid.RowSpan="5" FontWeight="Bold" Grid.Column="8" Height="143" VerticalAlignment="center" Width="218" HorizontalAlignment="Left" Grid.ColumnSpan="3" ShowBorder="False" Margin="0,0,0,7">
<dxe:ListBoxEdit.StyleSettings>
<dxe:RadioListBoxEditStyleSettings />
</dxe:ListBoxEdit.StyleSettings>
and this is how im populating the buttons
private void InitSources()
{
List<String> source = new List<String>();
source.Add("Split Freight");
source.Add("Print Comment");
source.Add("Do Not Split Freight");
xrbSplitFreight.ItemsSource = source;
}
I have tried numerous properties like padding and margin properties and it doesn't change the spacing.

If I understand you correctly, what you want is to increase the space between each radiobox and its text so it matches the space between the checkbox and its text above.
The problem here is that the radiobox content does not have a margin property to move it independently from the radiobox. Luckily in WPF you can encapsulate almost every control in any other control. So the solution, instead of using simple text, is to use a control that can display text and has a margin property like this:
<RadioButton GroupName="GroupName">
<RadioButton.Content>
<TextBlock Text="Option 1" Margin="5 0 0 0"/>
</RadioButton.Content>
</RadioButton>

Try using Margin to add space between controls.
<RadioButton Margin="5"></RadioButton>
or
<RadioButton Margin="5,0,5,0"></RadioButton>
EDIT
Check this out.
<ListBox ItemsSource="MyList">
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton Margin="10" Content="{Binding Value}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Each RadioButton is separated with margin given.

I think the problem is You're trying to place radio buttons inside of ListBox. Have You tried putting them into StackPanel with vertical orientation property? If You'll try You'll probably be able to set margins between them.

Related

How to make a border around a stackpanel which stops at the last element inside it?

Currently I have a stackpanel with 2 buttons which I have placed in a single row whithin my grid. I want to draw a border around the stackpanel, but the stackpanel is filling the whole row, it doesnt stop at the last button (as expected I suppose):
Image of border around stackpanel
How can I modify this so the stackpanel or border stops at the last element without hardcoding or dynamically calculating a bottom margin?
<Border Background="#FF303841"
Margin="5"
CornerRadius="3"
Grid.Row="2"
Grid.Column="4">
<StackPanel>
<TextBlock Text="OTHER"
Foreground="White"
FontWeight="Medium"
FontFamily="Poppins"
FontSize="16"
HorizontalAlignment="Left"
Margin="5,5,0,0"/>
<Button Style="{StaticResource linkBtn}">TEST1</Button>
<Button Style="{StaticResource linkBtn}">TEST2</Button>
</StackPanel>
</Border>
As per emoacht's comment above, the solution was to simply add VerticalAlignment="Top" to the border. That made it stop filling the parent which was the grid row.
The cause of this behavior is that the default parameter for VerticalAlignment is stretch, so it needs to be overridden.

WPF textBox changes color halfway

I have a strange problem with the textBox in WPF. I have a simple textbox inside a stackpanel binded with some text on the code behind. When the text becomes too long some part of it changes color. Here is an example
The stackpanel is this
<StackPanel Canvas.Left="50" Canvas.Top="111">
<TextBlock Text="{Binding Title}" FontSize="32" Foreground="White" />
<TextBlock Text="{Binding Subtitle}" FontSize="15" Foreground="#9EA3AA"/>
</StackPanel>
How can I make all the text white?
As mentioned by Clemens you are experiencing overlap. To fix this make the cell containing the orange cpu image and text not extend so high. You should be able to just drag and drop.

TabControl position TabItems

I have TabControl.
I want move tabs to the left but window with content should not change the size.
Result:
My code:
<controls:TabControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" x:Name="MyTabControl" BorderBrush="Transparent" BorderThickness="0" Padding="0">
<controls:TabControl.Resources>
<DataTemplate x:Key="ClosableTabItem">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="textBlockName" VerticalAlignment="Center" Text="{Binding}"/>
<HyperlinkButton Margin="6,0,0,0" x:Name="tabItemClose" VerticalAlignment="Center"
Click="tabItemClose_Click">
</HyperlinkButton>
</StackPanel>
</DataTemplate>
</controls:TabControl.Resources>
<controls:TabItem Header="Main" x:Name="MainTabItem" ToolTipService.ToolTip="Main" >
</controls:TabItem>
</controls:TabControl>
I won't really post a huge answer with a lot of XAML , rather i will give you some basic ideas of what you can do :)
1.Inside each tabitem,just add a grid and create two columns.Place every required element in the middle column and make sure the Grid's HorizontalAlignment and VerticalAlignment are set to Stretch
You can customize the template of your tabcontrol and set required width/margin of TabPenl/ContentPresenter.
I think 1 is the easiest solution so far,if you want to use 2 , leave a comment and i'll add some helpful XAML
Hope this helps :)

WPF DockPanel: cannot select it to add children

I have created a few text boxes that have to be added as children to my DockPanel. I have given this DockPanel a name and then when I try in my code to use this name, Intellisense does not give me any results. How do I select DockPanel and then add its children?
I want to select it and add some text boxes to it as its children. For example: nameLocationPanel.Children.Add(new TextBox());
This is the top part of my XAML code that contains the DockPanel. It already has some text boxes, but I want to add more in my C# code.
<ListBox ItemContainerStyle="{StaticResource lbStyle}" Name="searchList" BorderBrush="#FF898989" BorderThickness="2" MouseUp="searchList_MouseUp" MouseDoubleClick="searchList_MouseDoubleClick" Visibility="Visible">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<DockPanel Name="nameLocationPanel">
<TextBlock FontSize="14" HorizontalAlignment="Left" Text="{Binding Path=FirstName}"/>
<TextBlock FontSize="14" HorizontalAlignment="Left" Text=" "/>
<TextBlock FontSize="14" HorizontalAlignment="Left" Text="{Binding Path=LastName}"/>
<TextBlock HorizontalAlignment="Right" Text="{Binding Path=Location}"/>
</DockPanel>
It is within a DataTemplate, you can't select it by name at all as it doesn't exist in your Window, it's just a Template definition that will get repeated so there isn't 1 dockpanel but N, N being equal to how many items there are in your listbox and there could well be 0 dockpanels.
What exactly are you trying to achieve? Odds are you're going about it backward.
You cannot access to the DockPanel because it is a part of a DataTemplate. It is generated for every item in your ListBox so it is impossible to access to a single instance of it.
To add additional items to the DockPanel it is necessary to do it via something like a binding in XAML or a special UserControl. But it depend always on the ListBoxItem.

Autosizing ComboBox dropdown to content in Silverlight

I have this ComboBox in my Silverlight UserControl:
<ComboBox
AutomationProperties.AutomationId="cmbProjects"
Grid.Row="0"
Grid.Column="2"
ItemsSource="{Binding Projects}"
SelectedItem="{Binding SelectedProject, Mode=TwoWay}"
Style="{StaticResource DefaultComboBoxStyle}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<TextBlock Foreground="DarkRed" AutomationProperties.AutomationId="{Binding Number}" Width="100" Margin="0" Text="{Binding Number, Converter={StaticResource StringFormatter},ConverterParameter='\{0\}'}" />
<TextBlock AutomationProperties.AutomationId="{Binding Description}" Text="{Binding Description, Converter={StaticResource StringFormatter},ConverterParameter='\{0\} '}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
The lenghth of most of the items populating the combobox exceeds the width of the control. When I dropdown the list, the dropdown expands, but not fully to the width of the item content, resulting in content that is clipped a horizontal scrollbar. This does not happen with exact same combobox where content is within the original width of the control.
In WPF, I could simply set the width of the item container to auto; in Silverlight this results in a catastrophic error. I can set the with to a huge number, but the scroll still appears, regardless of the width. Also, in Silverlight 2 beta 2 there was a property DropDownWidth, with one of the options being "Auto", which I don't see in RTM.
I can get around this with a bit of trickery, mainly hiding the horizontal scrollbar and appending a bunch of characters so that the dropdown fully expand to show the item content. Obviously, this hack not ideal. Did anyone experience similar problem? Is there something that I'm missing to force the combobox to expand fully without a scrollbar?
ib.
It appears that they fixed it in SL3.
If you want to tweak the PopUp, you can do that from within the ComboBox's Control Template. In Blend follow these steps:
Right Click on ComboBox
Select "Edit Control Parts (Template)"
Select "Edit a Copy"
This will copy the out of the box control style & template so that you can tweak that ScrollViewer inside the ComboBox's PopUp to your heart's content.
You may want to try the solution I describe here. It details how to ensure that the combobox pop-up's height and width are updated when items are added or removed.
You can use MaxDropDownHeight property of ComboBox control.

Categories

Resources