I have set the VerticalContentAlignment, HorizontalContentAlignment and TextAlignment as Center as per the below code but the text is not aligned center in the TextBox.
<TextBox Text="Data" Width="200" Height="50" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" TextAlignment="Center"/>
How can i achieve this without padding?
The question title says TextBlock but the code show a TextBox, so try swapping the TextBox for a TextBlock, then set the TextAlignment property to "Center" (see below):
<TextBlock TextAlignment="Center">Data</TextBlock>
Hope that helps you.
Related
How can I design an underlined custom textbox in UWP. Example of such textbox is given below -
You could set BorderBrush="Purple" and BorderThickness="0,0,0,2" to change the border color and border thickness directly.
As follows:
<TextBox Width="150" Height="40" BorderBrush="Purple" BorderThickness="0,0,0,2">
<TextBox.Resources>
<!-- To also have the focused TextBox only have a border at the bottom,
we need to override this resource. -->
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0,0,0,2</Thickness>
</TextBox.Resources>
</TextBox>
I want to enable user to resize the NavigationView in my UWP app. Couldn't find any resources how I could do that.
I see some of the apps have "Resizable splitView" but for SplitView also, I cannot see any such resize property exposed to set by default.
Pls help.
Thanks in Advance
There are no such property can resize SplitView and NavigationView, you need to custom layout to implement a similar effect. You could use Slider control and bind the OpenPaneLength Property of SplitView to Slider.Value to do this. Please refer to the following code.
<Grid>
<SplitView Name="CoreSplitView"
DisplayMode="Inline"
IsPaneOpen="True"
OpenPaneLength="{Binding Value, ElementName=MasterSlider, Mode=OneWay}">
<SplitView.Pane>
<Grid Name="PaneGrid" Background="Gray">
<Slider Name="MasterSlider"
MinWidth="480"
VerticalAlignment="Stretch"
Maximum="480"
Minimum="10"
Opacity="0"
Value="150"
/>
<StackPanel Name="PaneStackPanel"
Margin="0,0,10,0" Background="LightGray">
<TextBlock TextWrapping="Wrap" Text="Use a slider when you want your users to be able to set defined, contiguous values (such as volume or brightness) or a range of discrete values (such as screen resolution settings).A slider is a good choice when you know that users think of the value as a relative quantity" />
</StackPanel>
</Grid>
</SplitView.Pane>
<Grid Name="ContentGrid" Background="LightSteelBlue">
</Grid>
</SplitView>
</Grid>
The StackPanel that is directly under our slider, acts like a cover for our Slider. Notice the StackPanel has Margin="0,0,10,0", this translates to a 10px distance from the right wall, which allows the Slider area to be exposed as a gray strip that is used to drag the Pane, again the 10px is arbitrary but it has to match the Minimum of the Slider.
I have added a ListView to a Metro Style Blank App. Added to the ListView are 3 Strings. I want to change the LineHeight , but cannot find a property. Below is my xaml code.
<Grid Background="{StaticResource ApplicationPageBackgroundBrush}">
<ListView HorizontalAlignment="Left" Height="277.167" Margin="235.51,161,0,0" VerticalAlignment="Top" Width="100" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
<ListView.RenderTransform>
<CompositeTransform SkewX="-0.338" TranslateX="-0.327"/>
</ListView.RenderTransform>
<x:String>test 1</x:String>
<x:String>Test2</x:String>
<x:String>Test3</x:String>
</ListView>
</Grid>
How do I decrease, increase the line height of the strings in the ListView box? I want to decrease the space between the lines.
Thanks
Try editing a ItemContainerTemplate and then play with the properties available like margin and padding.
See my answer here :
WPF ComboBox customization in windows8
let me know in case you need any help.
I have a question on Windows Phone 7 XAML programming.
<StackPanel Orientation="Vertical" Width="110">
<Canvas Margin="0">
<TextBlock Text="{Binding Menesis}" Foreground="{Binding MyColor}"></TextBlock>
</Canvas>
<Canvas Margin="0,12,0,0">
<TextBlock Text="{Binding Datums}" Foreground="{Binding MyColor}" FontSize="85" HorizontalAlignment="Center" TextAlignment="Center" />
</Canvas>
<Canvas Margin="0,105,0,0">
<TextBlock Text="{Binding Nedelas_diena}" Foreground="{Binding MyColor}" />
</Canvas>
</StackPanel>
How to make TextBlock (Binding Datums) text centered? Currently it is aligned at right side and
HorizontalAlignment="Center"
or
TextAlignment="Center"
doesn't work.
If you have your TextBlock in a Canvas you will have problems with the alignment as the TextBlack will be placed at 0,0 (top left) inside the canvas control and (unless you set the width explicitly) will be stretched to fit the text contained. This basically means your text will always be left aligned.
The Canvas control should only be used when you need to set the exact position of the contained elements. If this is not the case then use another container such as a Grid, StackPanel or even just a ContentControl.
Remove the Canvas from your xaml and it should work.
To clarify HorizontalAlignment vs. TextAlignment:
If you have a ContentControl that is 400px wide and you add a TextBlock to it that is set to be 200px wide with text content that is 100px wide, then the following is true:
Setting the HorizontalAlignment to Center will align the TextBlock (200px wide) to the middle of the ContentControl but the text will still be left aligned within the TextBlock. This means the text will be offset 100px from the left.
If just the TextAlignment is set to Center then the TextBlock will be left-aligned but the text inside will be centered. This means that the text will be offset 50px from the left.
In my opinion the best practise here is not to set any widths and just set the TextAlignment property. This will mean (for most containers) the TextBlock will be stretched the entire width of the container and the text within aligned appropriately.
Instead of using stack panel and canvas . either u can use Grid. If you are using grid you can point out the exact position where you need to place the control.
for eg,
<----- Height -->
like this. More over there is no need to use canvas. The canvas container is using mainly in case of game design purpose.
Is there any way to display scrollabletext in loose xaml? The equivalent in HTML would be
<div style="overflow:scroll">some long bit of text here</div>
Can you do this in loose xaml?
From my experiments so far it seems that in loose xaml:
You cannot use TextBox -- it must be TextBlock.
TextBlock doesn't seem to have any styling settings which would make it scrollable.
ScrollViewer doesn't seem to be allowed in loose xaml.
Any help gratefully appreciated.
You can use a textbox for scrolling text e.g.:
<TextBox Text="{Binding YourText}" VerticalContentAlignment="Top"
TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto"
MaxHeight="200" MaxWidth="300"/>
This will show scrollbars if your text doesn't fit in the displayed area.
<ScrollViewer Height="239" VerticalScrollBarVisibility="Auto">
<toolkit:PhoneTextBox x:Name="newcTextBox" AcceptsReturn="True" TextWrapping="Wrap"/>
</ScrollViewer>