am new to WPF MVVM, i had an issue with fit to window with zoom in and zoom out
for zoom in and zoom out it is working fine, but on clicking on fit to window content is not setting to actual window height and width. instead there is scrollbar which should not be displayed on fit to window content should be fit to window layout .. is there anything which can help me out.
<!-- Layout display area -->
<dxlc:LayoutItem Focusable="False"
VerticalAlignment="Stretch">
<Grid x:Name="LayoutGrid"
Margin="1">
<dx:ThemedBorder BorderThickness="1"
Margin="5,0,1,2">
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<ContentPresenter Content="{Binding DrawingSurface}"
Height="{Binding CanvasHeight}"
Width="{Binding CanvasWidth}"
VerticalAlignment="Top">
<ContentPresenter.ContextMenu>
<ContextMenu ItemsSource="{Binding WorkingCanvas.ContextMenuItems}" />
</ContentPresenter.ContextMenu>
</ContentPresenter>
<b:Interaction.Triggers>
<b:EventTrigger EventName="SizeChanged">
<b:CallMethodAction MethodName="OnSizeChanged"
TargetObject="{Binding}" />
</b:EventTrigger>
</b:Interaction.Triggers>
</ScrollViewer>
</dx:ThemedBorder>
</Grid>
</dxlc:LayoutItem>
Related
I have a ListView populated with ListViewItems, like navigation bar style menu options.
I would like to create the effect of the ListViewItem border "bulging" like in the Mail application on Win10 as shown in this picture
The border "bulges" (fisheye?) as the mouse moves left and right along the ListViewItem. It's a nice effect that I'd like to replicate but am struggling to even get started on how to tackle this.
My list items are bound to a content control which is templated with a ControlTemplate. The ItemsControl ItemTemplate is a DataTemplate containing an image and a Textbox wrapped inside a button control, like this .... (although I suspect how it's created is probably not relevant to my question)
<ContentControl Content="{Binding Path=MenuModel.AllMenuItems}"
x:Name="menuCtrl1"
Template="{StaticResource MenuListItemControlTemplate}"
VerticalAlignment="Top" />
...
<ControlTemplate x:Key="MenuListItemControlTemplate" TargetType="ContentControl">
<Border Background="Transparent" >
<ScrollViewer Margin="{StaticResource DefaultNoMargin}" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{TemplateBinding Content}"
ItemTemplate="{StaticResource MenuListItemDataTemplate}" />
</ScrollViewer>
</Border>
</ControlTemplate>
...
<DataTemplate x:Key="MenuListItemDataTemplate" DataType="local:SingleMenuItem">
<Button Command="{Binding MenuCommand}" Style="{StaticResource MenuButtonStyle}" >
<StackPanel Orientation="Horizontal" >
<Image Source="{Binding MenuIconSource}" Style="{StaticResource MenuItemImage}" />
<TextBox Text="{Binding DisplayText}" Style="{StaticResource MenuItemStyle}" />
</StackPanel>
</Button>
</DataTemplate>
Any tips on how to achieve it or even where to start would be gratefully received.
I'm creating a popup menu a ToggleButton and a Popup control. All of which are contained within a canvas. The following image is of the bottom right corner of my application. I set my Canvas so that's in the Index 1 column, stretches 2 columns, and is in the second to bottom row.
The gray image is just a place holder. From the XAML below, you can see that I've set everything to stretch. The Canvas stretches, but nothing else does. Commenting out the StackPanel and/or the Label does nothing. So I'm convinced neither are the cause. The ToggleButton isn't stretching to the size of the Canvas.
I did a screenshot so I could highlight those relevant portions, better. But if I need to paste the code, I can.
EDIT
Updated XAML:
<Border BorderBrush="Green" BorderThickness="1" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid Name="ToggleButtonCanvas" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ToggleButton x:Name="btnPluginMenu" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ToggleButton.Template>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="bdr" BorderThickness="0">
<Border.Background>
<ImageBrush ImageSource="< omitted >" Stretch="Fill" TileMode="None" />
</Border.Background>
<ContentPresenter VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="8,6,8,6" ContentSource="Content" />
</Border>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<Label Canvas.Left="10" Canvas.Top="10" Content="Menu" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
</StackPanel>
<Popup Placement="Relative" HorizontalOffset="-120" VerticalOffset="-130" PlacementTarget="{Binding ElementName=btnPluginMenu}" IsOpen="{Binding ElementName=btnPluginMenu, Path=IsChecked}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" PopupAnimation="Scroll">
<Grid Background="Gray">
<Grid.BitmapEffect>
<DropShadowBitmapEffect />
</Grid.BitmapEffect>
</Grid>
</Popup>
</Grid>
</Border>
Canvas does not stretch its child elements. Use a Grid instead.
From the Remarks in the Canvas documentation in MSDN:
Canvas is the only panel element that has no inherent layout
characteristics. A Canvas has default Height and Width properties of
zero, unless it is the child of an element that automatically sizes
its child elements. Child elements of a Canvas are never resized, they
are just positioned at their designated coordinates. This provides
flexibility for situations in which inherent sizing constraints or
alignment are not needed or wanted. For cases in which you want child
content to be automatically resized and aligned, it is usually best to
use a Grid element.
You can simply replace Canvas by Grid in your XAML. There is no need to define rows or columns.
I have a Dockpanel with items inside a Canvas. The Dockpanel and any other items (Grid etc) that I place inside the Canvas, only take up their minimum required space. How do I stretch these items to fill the entire Canvas?
<Canvas x:Name="InfoCanvas" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="72,53,0,0">
<DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" x:Name="ReferenceInfo" Canvas.Left="0" Canvas.Top="0">
<TextBox x:Name="ReferenceAuthor" GotFocus="FieldEnter" LostFocus="FieldLeave" FontSize="16" FontFamily="Segoe UI Light" Text="Author" Foreground="Gray" Background="Transparent" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0,2,0,2"/>
<TextBox x:Name="ReferenceTitle" GotFocus="FieldEnter" LostFocus="FieldLeave" FontSize="16" FontFamily="Segoe UI Light" Text="Title" Foreground="Gray" Background="Transparent" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0,2,0,2"/>
<TextBox x:Name="ReferenceDate" GotFocus="FieldEnter" LostFocus="FieldLeave" FontSize="16" FontFamily="Segoe UI Light" Text="Date" Foreground="Gray" Background="Transparent" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" BorderThickness="0" Margin="0,2,0,2"/>
</DockPanel>
</Canvas>
Thank you!
The Canvas panel doesn't really support that.
It's very basic - it just allows you to position children absolutely by using Top, Bottom, Left and Right, and it always gives them just the space they need.
So usually you would use a Grid with just 1 column and 1 row instead.
You can however bind the width and height of the DockPanel to the width and height of the Canvas. That way the DockPanel will always fill the Canvas.
<DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Margin="0,0,0,0" x:Name="ReferenceInfo" Canvas.Left="0" Canvas.Top="0"
Width="{Binding ActualWidth, ElementName=InfoCanvas}"
Height="{Binding ActualHeight, ElementName=InfoCanvas}">
What you can do is:
<Grid>
<Canvas x:Name="InfoCanvas">
<!--Elements with canvas layout here-->
</Canvas>
<DockPanel x:Name="ReferenceInfo">
<!--Elements with dockpanel layout here-->
</DockPanel>
</Grid>
By wrapping both panels in a grid like this you can place elements that you cant to position relative to left, top etc in the canvas. Both the canvas and the dockpanel will fill available space. Note that the elements in the dockpanel will be rendered above the elements in the canvas when the dockpanel is defined after in xaml.
I'm assuming the code you posted is pseudo code, if not you should just remove the canvas.
I have a parent container that is used to hold all of my user controls. The issue is that I use VerticalAlignment="Stretch" to stretch contents to the full height and get a vertical scroll bar the user control gets stretched too much. The vertical scrollbar appears but there is no way to scroll. I know this because the down arrow for the scroll bar isn't visible.
I have <ContentControl Content="{Binding Workspace}" /> which is where a variety of controls can be assigned. For example, here is the XAML that is not working property in regards to stretching.
<StackPanel>
<TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" Margin="0 0 0 8" />
<ScrollViewer VerticalAlignment="Stretch">
<TreeView
ItemsSource="{Binding Listing}"
Grid.Row="1"
BorderThickness="0"
VirtualizingStackPanel.IsVirtualizing="True" />
</ScrollViewer>
</StackPanel>
I only want to the TreeView to stretch and display a vertical scrollbar.
Any ideas?
I suspect the height of the StackPanel is not contrained so it grows to accomodate the ScrollViewer. You can check this by putting a border on the StackPanel.
<Border>
<StackPanel>
<TextBlock Text="{Binding FoundCount}" FontSize="13" Foreground="#666" />
<ScrollViewer VerticalAlignment="Stretch">
<TreeView ItemsSource="{Binding Listing}" BorderThickness="0"
VirtualizingStackPanel.IsVirtualizing="True" />
</ScrollViewer>
</StackPanel>
</Border>
How to put text into circle in WPF XAML template?
There are a few ways to do it, like on Centering Text on a WPF Shape
Here's an example:
<Border CornerRadius="50"
Width="60"
Height="60"
Margin="10"
Padding="0,20,0,0"
Background="Aquamarine"
BorderBrush="Black"
BorderThickness="1">
<TextBlock HorizontalAlignment="Center">Test
</TextBlock>
</Border>