AvalonDock Layout Without DocumentPane - wpf

I am trying to create a layout with avalon dock which looks something like this:
On the left side, the user is supposed to select the content which is displayed in the red box. This sort of layout can be easily achieved if the red box in the middle is declared as Document pane, and the content is displayed as a tab.
However, usage of tabs in this case is not needed because there is only one content, so I want to display the red box as an anchorable instead as a document.
So, basically, I want a layout which does not contain the document pane at all.
This is my code so far:
<ad:DockingManager
LayoutUpdateStrategy="{StaticResource dockingLayoutStrategy}"
AnchorablesSource="{Binding Path=Anchorables}"
ActiveContent="{Binding Path=ActiveContent, Mode=TwoWay}"
>
<ad:DockingManager.LayoutItemContainerStyleSelector>
<local:DockingPaneStyleSelector>
<local:DockingPaneStyleSelector.AnchorableStyle>
<Style TargetType="{x:Type adc:LayoutAnchorableItem}">
<!-- a bunch of properties-->
</Style>
</local:DockingPaneStyleSelector.AnchorableStyle>
<local:DockingPaneStyleSelector.PaneStyle>
<!-- a bunch of properties-->
</local:DockingPaneStyleSelector.PaneStyle>
</local:DockingPaneStyleSelector>
</ad:DockingManager.LayoutItemContainerStyleSelector>
<adl:LayoutRoot>
<adl:LayoutPanel Orientation="Horizontal">
<adl:LayoutAnchorablePane Name="ContentSelectionPane" DockWidth="100"/>
<adl:LayoutPanel Orientation="Vertical" DockWidth="*" IsMaximized="True">
<adl:LayoutPanel Orientation="Horizontal">
<adl:LayoutAnchorablePane Name="MainPane" IsMaximized="True" />
<adl:LayoutAnchorablePane Name="PropertyPane" DockWidth="300"/>
</adl:LayoutPanel>
<adl:LayoutAnchorablePane Name="StuffPane" DockHeight="150"/>
</adl:LayoutPanel>
</adl:LayoutPanel>
</adl:LayoutRoot>
The first problem I am experiencing is that when the left pane is loaded, it takes all available space, and it never allows the right side to show. If I commment out the left side pane, the right side of the window is shown.
The second problem is that the panes do now have the size which I declared, but always take the half of the available size. E.g. if I have:
<adl:LayoutRoot>
<adl:LayoutPanel Orientation="Horizontal">
<adl:LayoutAnchorablePane Name="ContentSelectionPane" DockWidth="100"/>
<adl:LayoutAnchorablePane Name="{x:Static si:Panes.DocumentPane}" DockWidth="*" IsMaximized="True" />
</adl:LayoutPanel>
</adl:LayoutRoot>
Both panes take exactly half of the availalbe place.
Any ideas on how I might achieve the "DocumentPane" size behaviour which does not display tabs, but achorables?

Well, I have a major "hack" that I did which worked for me. I set a negative top-margin on the top of the container holding the document pane. The negative margin pulls the content up hiding the document tab well.
It is tricky because you have to do it after the content is rendered/loaded, because the Xaml panes are not the actual visuals put into the Visual Tree.
Here is my Xaml for the document area:
<xcad:LayoutDocumentPane
x:Name="LayoutDocumentPaneArea"
CanRepositionItems="False"
DockMinHeight="0"
DockMinWidth="0"
IsMaximized="True">
<xcad:LayoutDocument
CanClose="False"
CanFloat="False"
IsMaximized="True">
<Grid x:Name="DocumentArea" />
</xcad:LayoutDocument>
</xcad:LayoutDocumentPane>
Then in the window's Content_Rendered event call this function to strip away the document tabs and in my case a 1px border of the content I had hosted there:
private void TrimDocumentArea()
{
var border = DocumentArea.FindVisualAncestor<Border>();
if (border != null)
{
border = border.FindVisualAncestor<Border>();
if (border != null && border.Name == "ContentPanel")
{
border.Margin = new Thickness(-1, -21, -1, -1);
}
}
}

Related

WPF take screenshot of application including hidden content

Under the category "limitations of the technology":
I have received the requirement to have a screenshot button in my application that will take a screenshot and launch a printer dialog. Fair enough. My code achieves that. I simply take my window, and use a RenderTargetBitmap to render the window.
However, the requirement now states that it should include all content that is hidden behind scrollbars. Meaning, that in the screenshot the application should look "stretched" in order to eliminate scrollbars, and show all data. For instance in case there is a large list or datagrid, all the data should be visible.
Keeping in mind that WPF might be virtualizing and not rendering things that are not in view, is there any way I can achieve this requirement? Is there a possibility of rendering the visual tree to a seperate infinite space and taking a screenshot there? Something else?
In response to comments:
The screenshot button is on an outer shell that only holds the menu. Inside this shell any of 800+ views can be hosted. These views could contain datagrids, lists, large forms consisting of textboxes... anything. There is no way to tell what is 'inside' without walking the visual tree.
The functionality requested is similar to printing a webpage in your browser to PDF. It will also give you the entire DOM instead of just what you see in the limited view of the browser.
XAML:
<Grid>
<Button
x:Name="btnPrint"
Width="50"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="BtnPrint_Click"
Content="Print" />
<ScrollViewer Height="500" HorizontalAlignment="Center">
<Grid x:Name="toPrint">
<!--your code goes here-->
</Grid>
</ScrollViewer>
</Grid>
C#:
private void BtnPrint_Click(object sender, RoutedEventArgs e)
{
var pdialog = new PrintDialog();
if (pdialog.ShowDialog() == true)
{
System.Windows.Size pageSize = new System.Windows.Size { Height = pdialog.PrintableAreaHeight, Width = pdialog.PrintableAreaWidth };
toPrint.Measure(pageSize);
toPrint.UpdateLayout();
pdialog.PrintVisual(toPrint, "Print");
}
}

Adding buttons over windows border

How can I be able to place buttons over windows border.What I am trying to do is to place close and minimize buttons over the border in a WPF application in c#.Any one could please tell me how to do that.
The word 'Border' in the context of WPF may have two meanings. It may be the <Border> element, or it is possible you mean the area the defines the <Window> element. Which one is it?
If you just want to have a buttons on a <Border> element, just put it as the content of the element. If you have more than one buttons, you need to have a panel (e.g. <StackPanel>).
You cannot draw anything beyond the client area of a <Window> element. To have buttons outside the Window area, you should another Window (say 'toolwindow') with the buttons that you want. Most likely you want this toolwindow without caption and non resizable border: WindowStyle="None" ResizeMode="NoResize". Then, keep the tool window position in sync with your main window (best thing would be to bind the Left and Right properties of both Windows to Left and Right properties in a common data context. Don't forget to declare the Binding mode to BothWay).
EDIT (follow clarification from #Sarita):
So it is the first. By Content I meant the body of the XML element. Technically, it is the Child property of the Border element. The following two XAMLs are equivalent:
<Border Background="Green" Padding="5">
<StackPanel>
<Button>A</Button>
<Button>B</Button>
</StackPanel>
</Border>
<Border x:Name="Bord" Background="Green" Padding="5">
<Border.Child>
<StackPanel>
<Button>A</Button>
<Button>B</Button>
</StackPanel>
</Border.Child>
</Border>

image resizing and controls layout shifting

Can you give an idea on xaml layout such that image is on the right and some content on the right.
And when image becomes larger, so the content shifts to the right?
I could probably put a two columns grid and programmatically enlarge image and making column 0 bigger, but there is must be a proper way to do.
Use a control that doesn't automatically adjust the size of its children based on available space, such as a Horizontal StackPanel
<StackPanel Orientation="Horizontal">
<Image ... />
<ContentControl .... />
</StackPanel>
If I misunderstood you and you actually want the content to resize based on available space, then use a control that automatically adjusts the size of its children based on available space, such as a DockPanel
<DockPanel>
<Image DockPanel.Dock="Right" ... />
<ContentControl .... />
</DockPanel>
When I first started working with WPF, I found this article very useful for figuring out what sort of panels I wanted to use to layout my controls
Do you mean image on the left and additional content on the right? Use width = auto for column 0 and width = * for column 1.

Lockable Surface in WPF

I want a custom Control in WPF which have a appearance similar to HTML, we use for showing Images in the centre of the screen with the whole screen locked and only image is showing.
I dont want to show images, I want to show UserControls within this section.
Can someone give suggestions of this?
In your Window, put all your controls in a single Grid, with a Border control (that contains your image) as the last item in the Grid (which means it will display on top of the other items). Toggle its Visibility via binding or code. Adjust styles as required.
<Window>
<Grid>
<!-- window controls go here --->
<Border Visibility="..." Background="#80000000"> <!-- EDITED -->
<!-- overlaid image (and/or other controls) goes here --->
<Image
Source="..."
Width="..."
Height="..."
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<Grid>
</Window>
In Windows applications this is generally achieved using a modal dialog, i.e. you create a normal WPF window and show it using ShowDialog.

How to align the button at the leftmost side in a listbox control?

I am developing window phone 7 application. I am new to the silverlight. I am dynamically creating the button control and binding these all button controls to the listbox.
<ListBox x:Name="lstButtons" Margin="393,-28,-12,28" Background="Orange">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Content="{Binding ElementName}" Width="100" HorizontalAlignment="Right"></Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now I want to display the button control at the leftmost side means I want to display the button control near to the left border of the listbox. I want to display the button control which is aligned to the left. With my above code the the button control appears in the center in the listbox ? How should I align it to the left ? Can you please provide me any code or link through which I can resolve the above issue ? If I am doing anything wrong then please guide me.
Take a look at the sample XAML in the MSDN resource page here. You need to play with the HorizontalAlignment property of the element you are trying to align within the parent, perhaps fine tune the alignment by setting the margin property of the element.
This might not be very helpful, but I have found that using expression blend for layout/ui things like this is the easiest way to do it. You will have to drill into the list template then you can play around with alignments.
For this scenario you need to align the button dynamically. In the following code the button is aligned at the left side in the listbox control. It is aligned close to the left border of the listbox control.
Button AlphabetButton = new Button();
AlphabetButton.Margin = new Thickness(-10,-27,0,0);
AlphabetButton.Width = 80;
AlphabetButton.Height = 80;

Resources