I have the following XAML which displays correctly:
<GroupBox Name="RulesGroupBox" Header="Rules">
<StackPanel Name="RulesStackPanel"
HorizontalAlignment="Left">
....
</StackPanel>
</GroupBox>
I now want to make the header text bold using the following (which I know works in other projects):
<GroupBox Name="RulesGroupBox">
<GroupBox.Header>
<TextBlock FontWeight="Bold" Text="Rules"></TextBlock>
</GroupBox.Header>
<StackPanel Name="RulesStackPanel"
HorizontalAlignment="Left">
....
</StackPanel>
</GroupBox>
For some reason, in this project, this change has the effect of making the text displayed for the Header text "System.Windows.Controls.TextBlock" and not "Rules". The text is now bold but not displaying "Rules".
Any idea why the chagne would not show "Rules" in bold?
You likely have changed GroupBox's HeaderTemplate and this template supports displaying only text.
Header is defined more than once.
<GroupBox Name="RulesGroupBox">
<GroupBox.Header>
<TextBlock FontWeight="Bold" Text="Rules"></TextBlock>
</GroupBox.Header>
<StackPanel Name="RulesStackPanel"
HorizontalAlignment="Left">
....
</StackPanel>
</GroupBox>
"Rules" appears in bold with this correction.
Edit : This answer was made for the question before it has been edited. It's clearly not the good answer for the edited question.
Related
How can I change the style of this button? I tried to use Style from the internet, but I got an error every time. I attach 2 screenshots, the original one and how it should look.
The original version
As it should be in the end
<Expander Header="1">
<Border Margin="50,0,0,0">
<StackPanel>
<TextBlock Text="6456567"/>
<TextBlock Text="6456567"/>
<Button Content="111"/>
</StackPanel>
</Border>
</Expander>
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 :)
The text in my TextBlock is bound to an element in my code. However, when I first open my window, the Textblock is completely empty. As I add text, I need the ScrollViewer to allow me to scroll down the text, or automatically scroll down as more text is added. Using the MVVM, so no code behind would be ideal.
<StackPanel Grid.Column="0" Grid.Row="1" Margin="0 10">
<Label Style="{StaticResource LabelStyle}">Output</Label>
<ScrollViewer VerticalScrollBarVisibility="Visible" Height="100">
<TextBlock ScrollViewer.CanContentScroll="True" Height="100" VerticalAlignment="Stretch" TextWrapping="Wrap" Text="{Binding Path=ProcessingOutput}"/>
</ScrollViewer>
</StackPanel>
How can I make this happen? Is there a way to update the ScrollViewer so that it sees more text is beyond what I can see in the TextBlock and allows the user to scroll down, or allows me to set an autoscroll feature that scrolls down automatically as text is added via binding?
Thanks in advance!
scrollbar will work if you remove Height="100" from TextBlock
to make it scroll when Text changes other answers suggest to use ScrollViwer.ScrollToBottom() method, e.g. like this:
<ScrollViewer Name="scroll"
VerticalScrollBarVisibility="Visible"
Height="100">
<TextBlock ScrollViewer.CanContentScroll="True"
VerticalAlignment="Stretch"
TextWrapping="Wrap"
Text="{Binding Path=ProcessingOutput, NotifyOnTargetUpdated=True}"
TargetUpdated="Txt_OnTargetUpdated">
</TextBlock>
</ScrollViewer>
private void Txt_OnTargetUpdated(object sender, DataTransferEventArgs e)
{
scroll.ScrollToBottom();
}
I want to load multiple images inside a wrappanel, for each image I show a thumbnail and some image details with this code
<Border BorderThickness="1" BorderBrush="#FFD0D1D7" Padding="5" Margin="10,10,0,0">
<StackPanel Orientation="Horizontal">
<!--image and dimensions-->
<Grid Width="88" Height="55">
<Image Source="C:\img1.jpg" Width="88" Height="55"/>
<TextBlock Background="#B2000000" Foreground="White" Height="16" TextAlignment="Center" VerticalAlignment="Bottom">1280x1024</TextBlock>
</Grid>
<!--name, type and size-->
<StackPanel Orientation="Vertical" Margin="5,0,0,0" VerticalAlignment="Center">
<TextBlock Margin="1" Foreground="#FF787878">img13.jpg</TextBlock>
<TextBlock Margin="1" Foreground="#FF787878">Type: JPEG</TextBlock>
<TextBlock Margin="1" Foreground="#FF787878">Size: 321 KB</TextBlock>
</StackPanel>
</StackPanel>
</Border>
But the images are loaded at runtime, and I need some way to create instances of the above code to show the image, dimensions, name, type and size
I tried this solution https://stackoverflow.com/a/4991028/962284
StringBuilder sb = new StringBuilder();
// use xaml to declare a button as string containing xaml
sb.Append(#"<Border BorderThickness='1' BorderBrush='#FFD0D1D7' Padding='5' Margin='10,10,0,0'>
<StackPanel Orientation='Horizontal'>
<!--image and dimensions-->
<Grid Width='88' Height='55'>
<Image Source='C:\img1.jpg' Width='88' Height='55'/>
<TextBlock Background='#B2000000' Foreground='White' Height='16' TextAlignment='Center' VerticalAlignment='Bottom'>1280x1024</TextBlock>
</Grid>
<!--name, type and size-->
<StackPanel Orientation='Vertical' Margin='5,0,0,0' VerticalAlignment='Center'>
<TextBlock Margin='1' Foreground='#FF787878'>img13.jpg</TextBlock>
<TextBlock Margin='1' Foreground='#FF787878'>Type: JPEG</TextBlock>
<TextBlock Margin='1' Foreground='#FF787878'>Size: 321 KB</TextBlock>
</StackPanel>
</StackPanel>
</Border>");
FrameworkElement thumb = (FrameworkElement)System.Windows.Markup.XamlReader.Parse(sb.ToString());
ThumbnailContainer.Children.Add(thumb);
but I get the following error
I also tried with styles, but styles doesnt support multiple parameters (to specify the textblocks: dimensions, size, name, type and size) just "TemplateBinding Tag" for 1 value
What can I do to create instances of the first code to show multiple images at runtime?
Wow. That so looks like the hard way to do things. Time to embrace WPF and XAML.
I had a post about this exact same thing that wasn't quite finished. I took time to finish it for you. I even used your XAML snippet (well, a modified version of it) in the example, just for you.
http://www.wpfsharp.com/2012/10/23/displaying-images-from-a-folder-with-details-in-wpf/
Clemens is correct in his comment to use an ItemsControl.
Yes your approach is wrong and you should be doing this some other way but to get your code snippet to work try adding xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" to your Border element in the string you are building. I suspect that is the error.
In a WPF application I load news from an RSS feed. The contents are displayed in a TextBlock. This TextBlock has a certain size. Contents are cut off by the TextTrimming method.
Now I would like at the end of each TextBlock to insert a hyperlink button. The only problem is I do not know exactly what position will be cut on my string. Is there a way to figure this out?
When I insert my Text in my TextBlock and then my Hyperlink-Button, my HyperlinkButton will be cut of. Can I prevent to cut off my HyperlinkButton?
XAML-Code:
<TextBlock Name="myText" />
C#-Code:
Hyperlink hlink = new Hyperlink(new Run("here"));
myText.Inlines.Clear();
myText.Inlines.Add(value); //description from RSS Feed
myText.Inlines.Add(hlink);
Why not just add the HyperLink after the text, by replacing both items in a StackPanel?
If I understood your requirements this is one way to achieve your goals:
<StackPanel>
<DockPanel Width="200">
<TextBlock DockPanel.Dock="Left" Text="A short description." TextTrimming="CharacterEllipsis"/>
<TextBlock DockPanel.Dock="Right" TextAlignment="Right">
<Hyperlink NavigateUri="http://www.google.com">here</Hyperlink>
</TextBlock>
</DockPanel>
<DockPanel Width="200">
<TextBlock DockPanel.Dock="Left" TextTrimming="CharacterEllipsis" MaxWidth="170" Text="A really long descripion of the item." />
<TextBlock DockPanel.Dock="Right" TextAlignment="Right">
<Hyperlink NavigateUri="http://www.google.com">here</Hyperlink>
</TextBlock>
</DockPanel>
</StackPanel>
So the DockPanel control might be a good candidate to consider.
Slightly more convenient is to use a :
<TextBlock>
<Run Text="Short description"/>
<Hyperlink NavigateUri="http://www.google.com">here</Hyperlink>
</TextBlock>