I have implemented simple zoom control in my project using Slider control:
<Grid Grid.Row="1" Grid.Column="0" Margin="5,5,5,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button Name="ZoomIncButton" Content="+" Margin="2" Grid.Row="0" Click="ZoomIncButton_Click"/>
<Slider x:Name="ZoomCtrl" Orientation="Vertical" Grid.Row="1"
Minimum="0.0" Maximum="8.0" LargeChange="0.15" SmallChange="0.01" Value="1.0"/>
<Button Name="ZoomDecButton" Content="-" Margin="2" Grid.Row="2" Click="ZoomDecButton_Click"/>
</Grid>
I would like to implement a minimap which can show where exactly user is on the zoomed UI. I do not want to use any 3rd party controls.
Please let me know if there are any sample/starter code for the same.
Thanks,
RDV
I found the solution via this project:
http://www.codeproject.com/Articles/85603/A-WPF-custom-control-for-zooming-and-panning
I was looking for some ideas to implement Overview window which are clearly described here.
Thanks,
RDV
Related
I have a WPF Window which has a Tab Control, in the third row of Grid, which contains a DataGrid. The DataGrid is being populated with data from EF and when the data is loaded, the DataGrid is going beyond the bounds of the window.
I've tried various solution (e.g. setting the Vertical/Horizontal Alignments to Stretch) but nothing I have tried worked. Below is a snippet of code up to the first open tag of the DataGrid (there are actually three tabs each with a DataGrid, but they are all the same, just bound to a different data source). With the below XAML, the width binds correct (i.e. the DataGrid doesn't go beyond the right side of the window) but the horizontal part of the DataGrid does go beyond the bottom of the window:
<Grid Margin="5,0,5,0" Background="Blue" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<user_controls:Spinner x:Name="spinner" Grid.RowSpan="3" Panel.ZIndex="1000"/>
<Menu Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top">
<MenuItem Header="Exit" Click="Exit_Click"/>
<MenuItem Header="Save" Command="{StaticResource SaveCommand}"/>
</Menu>
<GroupBox Grid.Row="1" Header="Server Type" Margin="610,0,0,0">
<StackPanel Orientation="Horizontal" Margin="0,5,0,0" HorizontalAlignment="Right">
<RadioButton x:Name="rbTestServer" GroupName="ServerType" Content="TEST" Foreground="Red" IsChecked="true" Checked="ServerType_Checked"/>
<RadioButton x:Name="rbProductionServer" GroupName="ServerType" Content="PRODUCTION" Foreground="Green" Margin="10,0,10,0" Checked="ServerType_Checked"/>
</StackPanel>
</GroupBox>
<TabControl x:Name="tcTables" BorderBrush="Red" BorderThickness="5" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinHeight="371" Height="auto" MinWidth="782" Width="auto" SelectionChanged="TcTables_SelectionChanged">
<TabItem x:Name="tiChargeType" Header="Charge Type">
<DataGrid x:Name="dgChargeType" Background="#FFE5E5E5" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding Source={StaticResource vsChargeType}}" Margin="2,10,10,10" RowDetailsVisibilityMode="VisibleWhenSelected" CellEditEnding="CellEditEnding">
Any help/suggestions would be greatly appreciated.
Thank You
You have three rows in your grid:
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
Because the third is set to Auto height, it tells it's content to go as big as it likes.
This is the cause of your problem.
Change that to:
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
Then your tab control and hence the datagrid in it will have a height limited to whatever is left after rows 0 and 1.
I've got a simple WPF application that has defined as
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" >
<Label Content="Date" Margin="5,0,0,0"/>
<DatePickerTextBox ></DatePickerTextBox>
<DatePickerTextBox ></DatePickerTextBox>
<DatePickerTextBox ></DatePickerTextBox>
<Button Margin="15,0,0,0" Content="Click me" Height="25" />
</StackPanel>
<Grid Background="Aqua" Grid.Row="1"></Grid>
</Grid>
(Please don't consider the sense of it, it's a mockup to reproduce the issue I'm facing in real app)
It shows as
When I resize it shows as
I wish that the stackpanel' s item float down in order to continue to see all of them, is this possible? how?
As #Rise said in the comments the correct panel to use in this case is a wrappanel not a stackpanel. A good overview of the different panel types can be found here
I'm really new to XAML and Metro and my old HTML skills are not in my advance.
What i want to achive is to have 3 "rows", the top row as some kind of header, the last row as some kind of footer and then a scrollable content area in the middle.
How can I achive this in XAML for Metro?
I've tried the StackPanel but I can't get the middle one to stop expanding and putting my "footer" out or the screen.
read more about WPF Layouts,
Grid in WPF is similar to Table in HTML, you should do this if you want header and footer.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/> <!--Header-->
<RowDefinition/>
<RowDefinition Height="50"/> <!--Footer-->
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Header"></TextBlock>
<ScrollViewer Grid.Row="1">
<!--your Controls-->
</ScrollViewer>
<TextBlock Grid.Row="2" Text="Footer"></TextBlock>
</Grid>
Try this,
<Grid x:Name="GridName">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*" />
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Header"/>
<StackPanel Orientation="Vertical" Grid.Row="1">
<!-- Other Controls -->
</StackPanel>
<TextBlock Grid.Row="2" Text="Footer" />
</Grid>
In a nutshell what Im trying to achieve is to have a re-usable DLL which will potentially have a wizard like form. I could then simply set the content. Ive spent quite a bit of time searching but Im still not sure whats the best way to go. Ive had a look at this article as well.
Ive got the following structure in the XAML code:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Content="{Binding ScreenTitleText}" />
<Label x:Name="ContentTitle" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Content="{Binding ContentTitleText}" />
<Button x:Name="BackButton" Grid.Row="5" Grid.Column="1" Content="Back" />
<Button x:Name="NextButton" Grid.Row="5" Grid.Column="3" Content="Next" />
<ScrollViewer Grid.Row="4" Grid.Column="2" Content="{Binding InnerContent}" x:Name="InnerControl"/>
</Grid>
Id like to know how to make it so that I could set the content on row=4 and column=2 to say for example a set of radio buttons.
How to have this code in a DLL so that I could re-use it.
Thanks!
Create this as a WPF User Control in a Class Library or a WPF User Control Library. Then, put ContentControls where you want the dynamic stuff to go. You can expose DataTemplate properties for each of those ContentControls. The ContentControls can bind their Template to a DataTemplate and you should be good to go.
I am working on a WP7 app. Well on one of the pages I would like to have a question mark available for users to select. Only trouble I am having is keeping it in a set location. If real estate is available, I want it to be at the bottom right corner all the time. But if the user should need to scroll, I want that item to have to be scrolled to as well.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
....
<StackPanel Grid.Row="1">
<Image Source="/Images/question_mark.png" Stretch="None"
VerticalAlignment="Bottom" HorizontalAlignment="Right" />
</StackPanel>
</Grid>
So how can I keep an image/button at the bottom of the page? Do I need to change anything so that it will always be at the bottom if the user needs to scroll? I appreciate your help!
It sounds like you want the image to be on the bottom of the scrollable content. To do so, place a StackPanel inside of a ScrollViewer
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<ScrollViewer x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<Rectangle Height="400" Fill="Brown" />
<Rectangle Height="400" Fill="Green" />
<Image Source="/Images/question_mark.png" Stretch="None"
VerticalAlignment="Bottom" HorizontalAlignment="Right" />
</StackPanel>
</ScrollViewer>
</Grid>