I have this XAML fragment:
<!-- ... -->
<TabControl>
<TabItem>
<!-- ... -->
</TabItem>
<TabItem Header="Source" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True">
<FlowDocumentScrollViewer>
<FlowDocument>
<Paragraph>
<TextBlock
Text="{Binding Path=CurrentObject.Source}"
FontFamily="Consolas,Courier,Segoe UI"
FontSize="12"
/>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
</TabItem>
</TabControl>
<!-- ... -->
The problem is that the flow document does not scroll horizontally. I've been unable to enable that.
Any clues?
Thanks in advance.
There are a couple things here. The first being that using a control in the Paragraph functions differently than a Run that would wrap to fit your FlowDocument.
The second is that the FlowDocument will fit your FlowDocumentScrollViewer. If you add a control to it like you did, it will fit the width of the FlowDocument and viewer and the text will go beyond the TextBlock borders. This means that your document doesn't need a scroll bar; your TextBlock would. You can see this by setting the TextWrapping property of the TextBlock to Wrap.
To get around this, set the PageWidth to something beyond the limits of the viewer width like so:
<FlowDocumentScrollViewer>
<FlowDocument PageHeight="1056"
PageWidth="816">
<Paragraph>
<TextBlock
Text="{Binding Path=CurrentObject.Source}"
FontFamily="Consolas,Courier,Segoe UI"
FontSize="12"
/>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
or bind to your TextBlock:
<FlowDocumentScrollViewer>
<FlowDocument PageHeight="1056"
PageWidth="{Binding ElementName=Part, Path=ActualWidth}">
<Paragraph>
<TextBlock
Text="{Binding Path=CurrentObject.Source}"
FontFamily="Consolas,Courier,Segoe UI"
FontSize="12"
/>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
The last thing is that the FlowDocumentScrollViewer has it's own HorizontalScrollBarVisibility property that you can use for this (unless some styling issue prevents it).
Related
For some reason my Tab Control doesn't seem to work as described.
Instead of seeing this (From Mahapps site)
I see this
I have tried fiddling with every single property to try to get the scroll bar to go away and to have left/right scroll buttons as shown in the example, but absolutely nothing works.
What am I missing?
EDIT: - Added my XAML
<Controls:MetroAnimatedSingleRowTabControl Controls:TabControlHelper.IsUnderlined="True" Margin="5" ScrollViewer.PanningMode="Both" ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
<Controls:MetroTabItem Header="Thread Image Download">
</Controls:MetroTabItem>
<Controls:MetroTabItem Header="Random Board Stats">
</Controls:MetroTabItem>
</Controls:MetroAnimatedSingleRowTabControl>
It doesn't exist a style key for this TabControl. So you must add the resource dictionary to the place where you need it. So MahApps should solve this in the next releases (site note for me).
<Grid>
<Grid.Resources>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
</Grid.Resources>
<TabControl>
<TabItem Header="this tabcontrols tabs">
<TextBlock FontSize="30" Text="Content" />
</TabItem>
<TabItem Header="appear only on a single line">
<TextBlock FontSize="30" Text="Content" />
</TabItem>
<TabItem Header="if they are overflowing">
<TextBlock FontSize="30" Text="Content" />
</TabItem>
<TabItem Header="instead of wrapping them">
<TextBlock FontSize="30" Text="Content" />
</TabItem>
</TabControl>
</Grid>
Hope this helps.
I am working on WPF, i am display RichText data in RichTextBox for that have taken WindowsFormHost, inside that i am taking WinForm RichTextBox to display RichTextData which have Images + Text.
But while display that RichTextData images are align to Top and text are align to Bottom,
See in Image below, red circle is RichTextImage
i want to display images and Text in center. Like Below Image, the Red Circle is RichTextImage that is coming in center with text.
My XAML Code is:
<Window x:Class="WPFRichTextBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
Title="MainWindow" Height="600" Width="800" Background="LightBlue" xmlns:my="clr-namespace:WPFRichTextBox">
<Grid Loaded="Grid_Loaded">
<WindowsFormsHost Margin="0,424,0,22">
<wf:RichTextBox Text="RichTextBox" x:Name="richTbTest1" BorderStyle="None" Enabled="True" ForeColor="Black" Width="550" Multiline="True" />
</WindowsFormsHost>
</Grid>
</Window>
I have used WPF RichTextBox also, but in that also i am not able to Align text+Images in Center
<RichTextBox VerticalContentAlignment="Stretch" Height="158" HorizontalAlignment="Left" Margin="10,247,0,0" Name="richTextBox1" VerticalAlignment="Top" Width="754" />
You can use BaselineAlignment on a Run to center align the text. Here is an example:
<RichTextBox>
<FlowDocument>
<Paragraph>
<Run Text="Some text" BaselineAlignment="Center"/>
<Image Height="100" Width="100" Source="Images\Desert.jpg"/>
<Run Text="Some more text" BaselineAlignment="Center"/>
</Paragraph>
<Paragraph/>
<Paragraph>
<Run Text="Paragraph 2" BaselineAlignment="Center"/>
<Image Height="100" Width="100" Source="Images\Desert.jpg"/>
<Run Text="More text" BaselineAlignment="Center"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
EDIT:
To apply the formatting to the entire RichTextBox try calling this method after the RichTextBox is populated:
public void CenterText()
{
var text = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
text.ApplyPropertyValue(Inline.BaselineAlignmentProperty, BaselineAlignment.Center);
}
I was able to get this working with a Span with the BaseAlignment attribute set to "Center".
<RichTextBox>
<FlowDocument>
<Paragraph>
<Span BaseAlignment="Center">
Center My Image
<Image ... />
</Span>
</Paragraph>
</FlowDocument>
</RichTextBox>
Here is the XAML sample:
<StackPanel Orientation="Horizontal" >
<TextBlock VerticalAlignment="Bottom" Text="Text1" FontSize="20" />
<Image VerticalAlignment="Bottom" ... />
<TextBlock VerticalAlignment="Bottom" Text="Text2" />
</StackPanel>
The result is that the textblocks have different bottom-margins depending on their FontSizes, but I need them all to be on one bottom line with no margins. How to get it? In my case I cant use TextBlock + Runs.
Forget several blobks : the bottom position dépends of the font size.
But, in a single paragraph, write the flow of your objects
You should use something like this :
<RichTextBlock>
<Paragraph>
<Span FontSize="148">Hello</Span>
<InlineUIContainer>
<Image Source="Assets/Logo.png"></Image>
</InlineUIContainer>
<Span FontSize="36">again</Span>
</Paragraph>
</RichTextBlock>
I have a DataTemplate that I am using for a cell in a gridview. I would like to switch between the progress bar and the text/link block. Is there a way to hide an element so that it is removed from the flow and takes up no space while it is hidden (like "display:none" in CSS)? Is there a better way to approach this?
DataTemplate looks like:
<DataTemplate x:Key="DataTemplate2">
<StackPanel Height="40">
<TextBlock Visibility="{Binding ButtonVisibility}">
<Hyperlink Click="btn_Authorise">
<InlineUIContainer>
<TextBlock Text="{Binding Button}" />
</InlineUIContainer>
</Hyperlink>
</TextBlock>
<ProgressBar Value="{Binding Progress}"
Visibility="{Binding ProgressVisibility}"
Height="15"
Width="150"
Background="{DynamicResource NormalBrush}"
BorderThickness="0"
BorderBrush="#FF8D8D8D"
Style="{DynamicResource ProgressBarStyle1}" />
</StackPanel>
</DataTemplate>
Visibility.Collapsed is probably what you need (as opposed to Visibility.Hidden which still makes the control take part in layout calculations)
Also see the Visibility enumeration reference.
Yep.
Visibility is an enumeration, Visible, Hidden, and Collapsed.
Hidden is just non-visible, whereas Collapsed means it takes no space also
For some reason I am not able to use the TextFlow element in WPF. Is this element/control even available?
I am using VS 2008.
If you want to avoid the default chrome of the FlowDocument, you can specify the viewer yourself:
<FlowDocumentScrollViewer>
<FlowDocument>
<Paragraph>
<Run>Hello</Run>
<Run Background="Yellow">World</Run>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
There is no TextFlow element.
Were you looking for FlowDocument?
<ContentControl>
<FlowDocument>
<Paragraph>
<Run>Hello</Run>
<Run Background="Yellow"> World</Run>
</Paragraph>
</FlowDocument>
</ContentControl>
You can also use a TextBlock:
<TextBlock><Run>Hello</Run><Run Background="Yellow">World</Run></TextBlock>