I have a list of labels and values. For instance (this sample is for illustrative purposes):
Tim 0.333
Fred 0.357
Fernando 0.300
I would like to be able to add to this list and have the text shrink so the list will fill the available space but not exceed it. I would also like to be able to resize the window and have the list fill the available space. I tried using a Viewbox to accomplish this and failed in two different ways:
1) I tried using a grid and surrounding each label and value with a Viewbox. This maintained my spacing between the label and value, but the labels and values were different sizes. Here is the code for the user control that displays the player information:
<UserControl x:Class="Viewbox.Player"
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="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Viewbox Grid.Column="0">
<TextBlock FontSize="30" Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
</Viewbox>
<Viewbox Grid.Column="1" HorizontalAlignment="Right">
<TextBlock FontSize="30" Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Viewbox>
</Grid>
</UserControl>
And here is the result:
2) I tried surrounding the grid with the Viewbox. This sized the text as I wanted, but now my spacing was gone and each line was centered.
<UserControl x:Class="Viewbox.Player"
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="300" d:DesignWidth="300">
<Viewbox>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" FontSize="30" Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" FontSize="30" Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Grid>
</Viewbox>
</UserControl>
I have been dancing around this issue for a while now. Can anyone help me with this?
Thanks!
I was able to solve the problem by inserting a blank column. This preserves the alignment and font sizes (up to a point):
<UserControl x:Class="Viewbox.Player"
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="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Viewbox Grid.Column="0">
<TextBlock Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
</Viewbox>
<Viewbox Grid.Column="2">
<TextBlock Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Viewbox>
</Grid>
</UserControl>
Unfortunately, it breaks down a bit when the window is sized very tall:
However, for my purposes, I am able to limit the total height, so this is not a problem.
Related
I have code like this:
<Page
x:Class="App4.Views.AddPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App4.Views"
xmlns:conv="using:App4.Converters"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
DataContext="{Binding AddPageInstance, Source={StaticResource Locator}}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<conv:SalaryConverter x:Key="SalaryConverter"/>
</Page.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Padding="20" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Width="300">
<TextBox Text="{x:Bind Vm.Name, Mode=TwoWay}"
x:Name="CharactValidator"
Header="Name"
PlaceholderText="Type Name here"
extensions:TextBoxRegex.ValidationMode="Dynamic"
extensions:TextBoxRegex.ValidationType="Characters"/>
<TextBlock Text="{Binding (extensions:TextBoxRegex.IsValid), ElementName=CharactValidator}"/>
<TextBlock Text="Salary"/>
<TextBox Text="{x:Bind Vm.Salary, Mode=TwoWay, Converter={StaticResource SalaryConverter}}" PlaceholderText="Type Salary here"/>
<TextBlock/>
<TextBlock Text="Title"/>
<TextBox Text="{x:Bind Vm.Title, Mode=TwoWay}" PlaceholderText="Type Title here"/>
<TextBlock/>
<TextBlock Text="Surname"/>
<TextBox Text="{x:Bind Vm.Surname, Mode=TwoWay}" PlaceholderText="Type Surname here"/>
<TextBlock/>
</StackPanel>
</Grid>
The problem is that i have errors connected with extensions:
Unable to convert "Dynamic" to an object of type "Microsoft.Toolkit.Uwp.UI.Extensions.TextBoxRegex+ValidationMode"
Unable to convert "Characters" to an object of type "Microsoft.Toolkit.Uwp.UI.Extensions.TextBoxRegex+ValidationType"
Error Failed to set "Path"
After building the app, it works great. But i don't know how to delete those errors messages and why it appears. If any additional informations are required, please ask me.
Thanks,
Konrad
right click solution -> Clean Solution.
Repeat step 1
close visual studio and reopen it.
Rebuild the solution
<UserControl
x:Class="scintillauwp.ScintillaControlEx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:scintillauwp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400" SizeChanged="UserControl_SizeChanged" MinWidth="100" MinHeight="100">
<Grid x:Name="rootLayout">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<canvas:CanvasControl x:Name="canvas" Grid.RowSpan="2" Grid.ColumnSpan="2"
PointerWheelChanged="canvas_PointerWheelChanged" PointerMoved="canvas_PointerMoved" PointerPressed="canvas_PointerPressed" PointerReleased="canvas_PointerReleased" MinWidth="100" MinHeight="100" PointerEntered="canvas_PointerEntered" KeyUp="canvas_KeyUp" KeyDown="canvas_KeyDown" GotFocus="canvas_GotFocus" LostFocus="canvas_LostFocus" PointerExited="canvas_PointerExited" Draw="canvas_Draw_1" >
</canvas:CanvasControl>
<ScrollBar x:Name="VerticalScrollBar" Grid.Column="1"
IsTabStop="False"
Orientation="Vertical"
HorizontalAlignment="Right" Maximum="10000" Value="1000" ViewportSize="800" />
<ScrollBar x:Name="HorizontalScrollBar" IsTabStop="False"
Orientation="Horizontal"
Grid.Row="1" />
<Border x:Name="ScrollBarSeparator" Grid.Row="1" Grid.Column="1" Background="{ThemeResource SystemControlPageBackgroundChromeLowBrush}"/>
</Grid>
//Maximum="10000" Value="1000" ViewportSize="800"------ is test
Hello everyone,my English is not OK. I'm using google translation.
I'm transplanting scintill to UWP. The ScrollBar is not shown in the above code. I tried using ScrollViewer+CanvasVirtualControl,but it needs to modify scintill's code in EditView .
Thanks.
There are Thumb in the layout of the following figure
I have this grid:
<UserControl
x:Class="Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Background="#FF341616">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse
Name="Red"
Grid.Row="0"
Margin="10,10,10,10"
Grid.Column="0"
Fill="#73b43c"/>
</Grid>
</UserControl>
but when it scales, it distortes.
How can I fix it? I don't want to replace it with an image.
If you want something to scale without distorting, put it inside of a Viewbox:
<Viewbox Grid.Row="0" Grid.Column="0" Margin="10,10,10,10">
<Ellipse Name="Red" Width="100" Height="100" Fill="#73b43c"/>
</Viewbox>
The Stretch property of the Viewbox can be set various values, depending on how you want the content to stretch. You probably want Uniform, which would look like this:
I have the Problem, that my first red rectangular (see 1st third in picture) does not have the height of the ListViewItem, whereas the second one with the larger text has the same size. Also, there is a margin to the left, which was not defined by myself. A similar scenario seems to appear with a button, where the blue line doesn't fill the whole height of the button (2nd third in the picture).
What I Want to achieve is something like the green rectangular (3rd third in picture). Without a margin to the left, filling the whole possible height.
I also leave my XAML code here and of yourse my thanks in advance.
Picture showing the problem
<Page
x:Class="Testprojekt.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Testprojekt"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0">
<ListViewItem>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="Red" Width="5"/>
<TextBlock Text="red"/>
</StackPanel>
</ListViewItem>
<ListViewItem>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="Red" Width="5"/>
<TextBlock Text="red"
FontSize="36"/>
</StackPanel>
</ListViewItem>
</ListView>
<Button Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Top">
<StackPanel Orientation="Horizontal">
<Rectangle Fill="Blue" Width="5"/>
<TextBlock Text="blue"/>
</StackPanel>
</Button>
<StackPanel Orientation="Horizontal"
Grid.Column="2">
<Rectangle Fill="Green" Width="5"/>
<TextBlock Text="green"/>
</StackPanel>
</Grid>
</Page>
If I understand the requirements correctly, you could use Border to achieve what you want.
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="Red" BorderThickness="5, 0, 0, 0" >
<ListView>
<TextBlock Text="red"/>
<TextBlock Text="red"/>
<TextBlock Text="red"/>
</ListView>
</Border>
<Border Grid.Column="1" BorderBrush="Blue" BorderThickness="5, 0, 0, 0" >
<Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalContentAlignment="Top">
<StackPanel Orientation="Horizontal">
<TextBlock Text="blue"/>
</StackPanel>
</Button>
</Border>
<Border Grid.Column="2" BorderBrush="Green" BorderThickness="5, 0, 0, 0" >
<StackPanel Orientation="Horizontal">
<TextBlock Text="green"/>
</StackPanel>
</Border>
</Grid>
If you want to completely eliminate the space between the border stroke and your controls you can play around with Margins. For example, try
<ListView Margin="-10, 0, 0, 0">
I'm developing a custom ListBox item template and so far wrote this code:
<UserControl x:Class="Application.Test"
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"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image HorizontalAlignment="Right" Height="100" Grid.RowSpan="2" Grid.Column="1" VerticalAlignment="Center" Width="100" Source="ControlTemplates\arrow_white.png"/>
<TextBlock Name="Title" TextWrapping="Wrap" Grid.Row="1" Grid.Column="0" Height="auto" Width="auto" Grid.ColumnSpan="2" Margin="10,212,119,214"/>
</Grid>
Link to picture sample: http://s7.postimg.org/oeyl8gge3/Capture2.png
I want to make this ListBoxItem 200 px, but all content - rubber ( to support both orientations )
When i try to change d:DesignHeight="480" d:DesignWidth="480" to 200px it makes the ListBoxItem 200px but text dissapers...
What am i doing wrong?
You need to reverse the column definitions:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
This way right column will have fixed size since it is automatically resized to accommodate the Image control with fixed width. And the first column will now always stretch to use all space.
However, this is not enough. Each individual list box item has its own width. To ensure that each item has maximum width, use the following code:
<ListBo>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>