Why the text from the following TextBlock is not displaying. How can we have it displayed above the FlowDocument?
<Window x:Class="WPF_Test.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:WPF_Test"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<TextBlock Margin="5" Text="This text is from TextBlock"/>
<FlowDocumentReader>
<FlowDocument Background="GhostWhite" ColumnWidth="10000">
<List MarkerOffset="25" MarkerStyle="Decimal" StartIndex="1">
<ListItem>
<Paragraph Margin="10">Test Paragraph</Paragraph>
<List MarkerStyle="UpperLatin" Margin="0" Padding="0" >
<ListItem Margin="40,5,0,0">
<Paragraph>Test paragraph</Paragraph>
</ListItem>
<ListItem Margin="40,5,0,0">
<Paragraph>Test paragraph</Paragraph>
</ListItem>
<ListItem Margin="40,5,0,0">
<Paragraph>Test paragraph</Paragraph>
</ListItem>
</List>
</ListItem>
<ListItem>
<Paragraph Margin="10">Test paragraph</Paragraph>
</ListItem>
<ListItem>
<Paragraph Margin="10">Test paragraph</Paragraph>
</ListItem>
</List>
</FlowDocument>
</FlowDocumentReader>
</Grid>
</Window>
MainWindow Display:
Grid adds elements based on a row and column index. The child elements TextBox and FlowDocumentReader should be located in different column/row of the grid panel:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="5" Text="This text is from TextBlock"/>
<FlowDocumentReader Grid.Row="1">
....
</Grid>
Related
Cant make button in WPF app with image and text on it. My code is like this:
<Window x:Class="WindowR.One"
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:WindowR"
mc:Ignorable="d"
Title="One" Height="300" Width="300">
<Grid>
<StackPanel Orientation="Vertical">
<TextBlock Text="Click Here" />
<Image Source="D:\Skola\4. semester\TP\GIT folder\Visualko\Core\WindowR\Pictures\0.png" />
</StackPanel>
</Grid>
</Window>
But the text isnt above image..tried lots of tutorials from here..but none of them work properly
StackPanel arranges TextBlock next to Image. Try to use Grid
<Button Width="120" Height="50" >
<Grid>
<Image Source="D:\Skola\4. semester\TP\GIT folder\Visualko\Core\WindowR\Pictures\0.png" />
<TextBlock Text="Click Here"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid>
</Button>
I have the following XAML:
<Window x:Class="test_stacking.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">
<StackPanel Background="AliceBlue">
<Canvas Background="Red">
</Canvas>
<ListBox Width="200" VerticalAlignment="Bottom">
<TextBlock Text="One" />
<TextBlock Text="Two" />
</ListBox>
</StackPanel>
</Window>
I would like the Canvas to be on top, and the ListBox to be on the bottom. Since the default orientation for a StackPanel is vertical, I thought I would get the Canvas and the ListBox, in that order, stacked within the StackPanel.
But instead, I get what is shown below: the ListBox is on top, and the Canvas does not show at all. What am I doing wrong?
.NET FW 4 Client Profile, Windows 7, VS 2010.
If it is not mandatory to use StackPanel then you can achieve that by using Grid's * sizing.
Here is an example:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="500" Width="500">
<Grid Background="AliceBlue">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Canvas Background="Red">
</Canvas>
<ListBox Grid.Row="1" Width="200" VerticalAlignment="Bottom">
<TextBlock Text="One" />
<TextBlock Text="Two" />
</ListBox>
</Grid>
</Window>
Output:
Or
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="500" Width="500">
<Grid Background="AliceBlue">
<Canvas Background="Red">
</Canvas>
<ListBox Width="200" VerticalAlignment="Bottom">
<TextBlock Text="One" />
<TextBlock Text="Two" />
</ListBox>
</Grid>
</Window>
Output:
Since you haven't set any height or width to the canvas, the height and width for the canvas is set to zero and thats why its not shown in the UI.
Try this
<StackPanel Background="AliceBlue">
<Canvas Background="Red" Width="200" Height="200">
</Canvas>
<ListBox Width="200" VerticalAlignment="Bottom">
<TextBlock Text="One" />
<TextBlock Text="Two" />
</ListBox>
</StackPanel>
I'm working on a WPF desktop application. The MainWindow is a maximized window that has a menu with few menu items. I would like to display few controls within a groupbox on the center of the window. This groupbox contains controls depending on the menu item clicked. So the size of the groupbox should not be static. Is this possible?
Thanks
Try to define your XAML like this
<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" WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel>
<Button Content="Click" Height="30" Width="160"/>
<Button Content="Click" Height="30" Width="160"/>
<!--<Button Content="Click" Height="30" Width="160"/>-->
</StackPanel>
</GroupBox>
<Grid Grid.Row="1">
<TextBlock FontSize="26" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Text="MainUserWork Panel"/>
</Grid>
</Grid>
WPF beginner here. I'm trying to mimic the font style used in Visual Studio 2010 for menus. Under Windows XP menus look blurry.
How can my code be changed to get the same result?
<Window x:Class="Test_WPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="480" Width="640">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Menu IsMainMenu="True">
<MenuItem Header="_File" />
<MenuItem Header="_Edit" />
<MenuItem Header="_View" />
<MenuItem Header="_Window" />
<MenuItem Header="_Help" />
</Menu>
</Grid>
</Window>
Play around with the following parameters for your Window:
<Window x:Class="Test_WPF.MainWindow"
....
UseLayoutRounding="True"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType">
In my case, the blurring was caused by a DropShadowEffect applied on a wrapped Grid.
Removing this effect makes the blur issue disappear.
I want to to align listitem marker to the top, default is alignment to the bottom of the first
block.
My faulty code:
<Grid>
<FlowDocumentScrollViewer>
<FlowDocument>
<List MarkerStyle="Decimal">
<ListItem>
<BlockUIContainer>
<Grid>
<Rectangle Height="100" Fill="HotPink" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">Picture</TextBlock>
</Grid>
</BlockUIContainer>
<Paragraph>TextTextTextTextTextTextText</Paragraph>
</ListItem>
</List>
</FlowDocument>
</FlowDocumentScrollViewer>
</Grid>
<FlowDocumentScrollViewer>
<FlowDocument>
<List MarkerStyle="Decimal">
<ListItem>
<BlockUIContainer/>
<BlockUIContainer>
<Grid Margin="0,-10,0,0">
<Rectangle Height="100" Fill="HotPink" />
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">Picture</TextBlock>
</Grid>
</BlockUIContainer>
<Paragraph>TextTextTextTextTextTextText</Paragraph>
</ListItem>
</List>
</FlowDocument>
</FlowDocumentScrollViewer>