Good evening. I have been chasing an issue with DocumentViewer and don't know how to address it.
When you display a document in a DocumentViewer control, it displays a border and a shadow around the document and I do not know how to get rid of it.
I have written a control template, which I would have expected to have addressed the issue and it does not. Here it is:
<Style x:Key="MyDocStyle" TargetType="DocumentViewer">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DocumentViewer">
<Border BorderThickness="5" >
<Grid>
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" x:Name="PART_ContentHost"
Background="Transparent"
BorderBrush="Transparent" BorderThickness="0" Padding="0" >
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
What else am I missing? Thank you in advance.
Turns out, you don't need to alter the ControlTemplate at all. May I point out DocumentViewer.ShowPageBorders:
Indicates whether drop-shadow page borders are displayed
Usage:
<DocumentViewer ShowPageBorders="False"/>
Thank you very much. I'm not sure how I missed that. Nonetheless, thank you very much for your help!
Related
I know there is tons of these questions out there. But most of these solutions don't work in my situation. However after spending a day on it, I finally found a solution which works in my case. I just need somebody with deeper knowledge of XAML to explain to me and possibly the others what exactly happens here.
<Style x:Key="ListBoxItemStyleNoHighlighting" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ContentPresenter x:Name="contentPresenter"
Margin="{TemplateBinding Margin}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If somebody out there needs the xaml of how to use it, here it is
<ListBox Background="Transparent"
BorderThickness="0"
ItemTemplate="{StaticResource MyDataTemplate}"
ItemsSource="{Binding MenuSubItems}"
SelectedItem="{Binding MySelectedItem}"
ItemContainerStyle="{StaticResource ListBoxItemStyleNoHighlighting}">
So what is happening in that style? I haven’t seen anything like this before. After some research I found out that TemplateBinding is just setting up its values to the parent. Then why is that ContentPresenter even needed if it does not add anything to the style. It's worth to mention that without ContentPresenter, it simply does not work.
Kind Regards
Daniel
The concept of ContentPresenter is quite simple – it is a placeholder for any XAML content and it can be used to insert content at runtime.
Here is more.
I have UserControl in a window. When user walks window with "Tab" key user control gets focused and dashed border drawn around it. How to prevent this behavior?
Try it for an control set Focusable = "False". Example:
<Grid Focusable="False">
...
</Grid>
Or set the Style to focus yourself:
<Grid FocusVisualStyle="{x:Null}" />
Also, the Style of focus might be:
<Style x:Key="MyItemFocusVisual" TargetType="{x:Type Control}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Control}">
<Border SnapsToDevicePixels="True" CornerRadius="0" BorderThickness="5" BorderBrush="#7B2F81" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Using:
<Grid Focusable="True" FocusVisualStyle="{StaticResource MyItemFocusVisual}" ... />
Output
If you just want to keep it from accepting focus via Tabbing just declare it on the object via IsTabStop="False" or you can edit the control Template for it and get rid of the Focus changes.
It was my mistake. I had xaml:
<ContentControl>
<ScrollViewer name="viewport"/>
</ContentControl>
and "viewport.Content" was set to my UserControl from code-behind.
It was a ContentControl who draw the focus border. I removed it and left only a . Problem solved.
I am currently working with avalon dock v2, in the template of my document sources, i'm also putting in a docking manager.
Yes for each of my document, I want anchorable panes inside it. But when I try to do that, it doesn't work, it just shows the toString of the docking manager for each of the document, is there a way to fix that.
Also, how do i default dock my anchorable?
Thanks and Regards,
Kev84
In creating a template for the AvalonDock's LayoutDocument (via the LayoutDocumentControl) I also came across a similar issue. The solution was to set the ContentSource of the ContentPresenter to point to the Model property of my control. The code below illustrates it:
<!--The LayoutDocument is templated via the LayoutDocumentControl-->
<Style TargetType="{x:Type ad:LayoutDocumentControl}">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ad:LayoutDocumentControl}">
<ScrollViewer
Background="AliceBlue"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True">
<!--Make sure that the ContentSource points the Model Property of the Control-->
<ContentPresenter
Content="{Binding Path=Content, UpdateSourceTrigger=PropertyChanged}"
ContentSource="{Binding Path=Model, UpdateSourceTrigger=PropertyChanged}"
/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
A similar approach should apply to your case. This is just a temptative answer (since I am also new to AvalonDock 2.0), but it may be worth trying.
Live long and prosper!
i want to draw/add an image as a part of text in textbox in windows phone 7. I m not using Expression blend.
So where i can find the drawing objects as well as paint events in silverlight?
You can apply a background image to a lot of Silverlight elements with the following:
<TextBox x:Name="SearchBox" Text="Search" Height="70" Width="390">
<TextBox.Background>
<ImageBrush ImageSource="Images/MagnifyingGlass.png" Stretch="UniformToFill" />
</TextBox.Background>
</TextBox>
There is no way to add an image as part of a TextBox. Although I'm not entirely sure what you want to achieve.
Do you really mean TextBox? If so, the only option will be to restyle it so it have the image included as well.
Do you mean TextBlock? If so, and you're trying to include an image part way through a piece of text, you can wrap the image and the text either side of it in a WrapPanel.
You might want to override the template in order to define your own template. You can do this in the style:
<Style x:Key="textboxImage" TargetType="TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="ApplicationIcon.png" />
</Grid.Background>
<ContentControl x:Name="ContentElement" Foreground="{TemplateBinding Foreground}" Margin="{TemplateBinding Margin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You just need to set the style of your textbox to StaticResources textboxImage.
I just tested and it works fine.
Based on the following code :
<GroupBox>
<GroupBox.Template>
<ControlTemplate TargetType="{x:Type GroupBox}">
<ContentPresenter TextElement.FontSize="28" />
</ControlTemplate>
</GroupBox.Template>
<TextBlock>Test</TextBlock>
</GroupBox>
I was expecting "Test" to be displayed with FontSize=28. But it uses the default size instead.
If I remove the TextBlock like this :
<GroupBox>
<GroupBox.Template>
<ControlTemplate TargetType="{x:Type GroupBox}">
<ContentPresenter TextElement.FontSize="28" />
</ControlTemplate>
</GroupBox.Template>
Test
</GroupBox>
The text is now the displayed with 28 as FontSize.
Shouldn't the property value be inherited when I use a TextBlock ?
This other question How do I Change the FontFamily on a ContentPresenter? doesn't help, as it works only for default content too.
This question also : How do I Change the FontFamily on a ContentPresenter?.
Both works whe you use the default content handler, but fails when you manually create a textblock.
Edit: As demonstrated in this other question, I've tried by simply using a ContentControl :
<StackPanel>
<StackPanel.Resources>
<ControlTemplate x:Key="UsingBorderTemplate" TargetType="{x:Type ContentControl}">
<Border BorderBrush="Red" BorderThickness="1" TextElement.FontFamily="Courier New" Margin="5">
<ContentPresenter/>
</Border>
</ControlTemplate>
<ControlTemplate x:Key="MyTemplate" TargetType="{x:Type ContentControl}">
<ContentPresenter TextElement.FontFamily="Courier New" Margin="5" />
</ControlTemplate>
</StackPanel.Resources>
<ContentControl Template="{StaticResource MyTemplate}">
I'm courier new!
</ContentControl>
<ContentControl Template="{StaticResource MyTemplate}">
<TextBlock>I'm default!</TextBlock>
</ContentControl>
</StackPanel>
You can change the template from "MyTemplate" to "UsingBorderTemplate" with the same result.
I had an odd problem with ContentPresenter. I remember that I have analyzed the source of the problem and have found out that it was by design - Probably you have here the same issue.
Look at this post, maybe it helps you.
I think the text that the content presenter is presenting is the GroupBox.Header, and you may just be tacking another TextBox in there that isn't part of the Group Box.
In your first code block, add the line below and see if that works:
<GroupBox.Header>Test</GroupBox.Header>
HTH,
Berryl