I have to draw something like a calendar.
I have a table where at top we see days and at left we see drivers' names.
And in a cell we see how many hours he works.
How to draw this table?
Also I need ability right clicking open driver's card.
How to do this also?
Thanks in advance!
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="1" Text="Mon" />
<TextBlock Grid.Row="0" Grid.Column="2" Text="Tue" />
<TextBlock Grid.Row="0" Grid.Column="3" Text="Wen" />
<TextBlock Grid.Row="0" Grid.Column="4" Text="Thu" />
<TextBlock Grid.Row="0" Grid.Column="5" Text="Fri" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="Driver X" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Driver Y" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Driver Z" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=DriverX.MonHours}" />
Check Micheal Snow's blog for the right clicking at http://www.michaelsnow.com/2010/04/23/silverlight-tip-of-the-day-3-mouse-right-clicks/
Related
I have a WPF app.
It has a grid that fills the whole page and there are 3 rows.
In the middle row I display a usercontrol depending on what menu button the User has chosen.
I want to create a rounded border around each Usercontrol and after Googling I found an example and implemented it.
It works but I get and inner rectangular border as well as the rounded outer border.
This is the markup inside my UserControl:
<Border BorderThickness="3" BorderBrush="White" CornerRadius="10" Padding="2"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid>
<Grid Background="White" >
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="220" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Content="Search for Customer" />
<Label Grid.Row="1" Grid.Column="1" Content="Enter Customer First Name"/>
<Label Grid.Row="3" Grid.Column="1" Content="Enter Customer Last Name" />
<TextBox Name="txtForeName" Grid.Column="1" Grid.Row="2" />
<TextBox Name="txtSurname" Grid.Column="1" Grid.Row="4" />
<Button Name="btnCustomerSearch" Grid.Column="1" Grid.Row="5" />
</Grid>
</Grid>
</Border>
and it gives me this appearance:
The inner rectangular border is not a border at all. You have the border (white) and the grid (white as well) inside it. The grid fits your border, but area between them doesn't have any color, so it is transparent, thus you see it blue. If you want the whole area white, set the border's background white. Also, in your code one of the nested grids looks redundant.
Edit: Looks like after setting the border's background you still have two border's lines. Just remove BorderThickness and BorderBrush (It's the same as set them default) and increase padding a little. Also, you don't need to set the background of the grid separately, it's already white from the border.
This is how I imagine it:
<Border CornerRadius="10" Padding="5" Background="White"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="220" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Content="Search for Customer" />
<Label Grid.Row="1" Grid.Column="1" Content="Enter Customer First Name"/>
<Label Grid.Row="3" Grid.Column="1" Content="Enter Customer Last Name" />
<TextBox Name="txtForeName" Grid.Column="1" Grid.Row="2" />
<TextBox Name="txtSurname" Grid.Column="1" Grid.Row="4" />
<Button Name="btnCustomerSearch" Grid.Column="1" Grid.Row="5" />
</Grid>
</Border>
I have changed the Border placement, and set its margin to -3.
Setting the Border background to White will still keep 4 corners of the Grid remaining Visible.
See if this works for you.
<Grid Canvas.Left="40" Canvas.Top="103">
<Grid Background="White">
<Grid Margin="5">
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="25" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="220" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Content="Search for Customer" />
<Label Grid.Row="1" Grid.Column="1" Content="Enter Customer First Name"/>
<Label Grid.Row="3" Grid.Column="1" Content="Enter Customer Last Name" />
<TextBox Name="txtForeName" Grid.Column="1" Grid.Row="2" />
<TextBox Name="txtSurname" Grid.Column="1" Grid.Row="4" />
<Button Name="btnCustomerSearch" Grid.Column="1" Grid.Row="5" Content="Press" />
</Grid>
</Grid>
</Grid>
<Border BorderThickness="3" BorderBrush="White" CornerRadius="10" Padding="2" Margin="-3"/>
</Grid>
The problem is the image is not fixed to the right side of the screen, so when I resize the screen it the image goes off screen, e.g.:
In that example we should see an image of a full phone.
I have the following Grid layout defined:
<Grid Background="White" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="23" />
<ColumnDefinition Width="166" />
<ColumnDefinition Width="473" />
<ColumnDefinition Width="330" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="35" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- some irrelevant stuff removed -->
<Canvas Grid.Column="3" HorizontalAlignment="Right" >
<Image HorizontalAlignment="Left" Name="imgLogo" Stretch="Uniform" VerticalAlignment="Center" Width="45" Height="45" Margin="30,135,0,0" Canvas.ZIndex="99" Canvas.Left="0" Canvas.Top="-7" />
<Image Source="/Resources/Images/MobileBrandingSample.png" Height="634" Width="316" HorizontalAlignment="Left" Margin="0,14,0,0" Name="imgPhone" Stretch="Uniform" VerticalAlignment="Top" />
<Label Canvas.Left="80" Canvas.Top="127" Content="" Height="20" Name="lblCompanyName" Width="169" FontSize="15" Padding="0,0,0,0" />
<Label Canvas.Left="80" Canvas.Top="150" Height="20" Name="lblPhoneNumber" Width="160" FontSize="12" Padding="0,0,0,0">
<TextBlock Name="tbPhoneNumberLabel" Text="" TextDecorations="Underline" Foreground="#35B6E5" Width="160"></TextBlock>
</Label>
</Canvas>
</Grid>
With this, imgPhone is right aligned, but when I resize the window imgPhone goes off screen. What do I need to keep imgPhone docked to the right of the screen, regardless of how the window is resized?
Ditch the Canvas, use a Dockpanel with a Grid inside it, dock the whole lot right and absolute sizing in the grid will keep things where you want them relative to everything else.
I tried this....and got a solution...maybe not exactly what you want but I think you can work out the few adjustments needed.
<Grid Background="White" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="company name"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Phone number"></TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Logo name"></TextBlock>
<Button Grid.Row="3" Grid.Column="0" Content="Upgrade branding"></Button>
<TextBox Grid.Row="0" Grid.Column="1"></TextBox>
<TextBox Grid.Row="1" Grid.Column="1"></TextBox>
<Button Grid.Row="2" Grid.Column="1" Content="Load logo"></Button>
<Image Grid.Column="2" Grid.RowSpan="4" HorizontalAlignment="Right" Source="C:\Users\somonteiro\Desktop\Montagens\somonteiro.jpg"></Image>
</Grid>
I am seeking examples for creating a standard dialog/Login windows with OK and Cancel buttons bottom right.
I am unsure whether to use StackPanels, Grids or dockpanels. I understand that it's normally not correct to use the Canvas due the fact that you have to enter x and y values.
What I have created so far is the buttons for the Ok and Cancel
<StackPanel Orientation="Horizontal"
FlowDirection="RightToLeft" Height="32">
<Button Width="72" TabIndex="45" Margin="2,2,2,2">Cancel</Button>
<Button Width="72" TabIndex="40" Margin="2,2,2,2">OK</Button>
</StackPanel>
The kind of windows I want to create are the standard Dialog windows.
I would prefer the following markup:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid Grid.ColumnSpan="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center">Username:</TextBlock>
<TextBlock VerticalAlignment="Center" Grid.Row="1">Password:</TextBlock>
<TextBox Grid.Column="1" />
<TextBox Grid.Row=1"" Grid.Column="1" />
</Grid>
<Button Grid.Row="1">Ok</Button>
<Button Grid.Row="1" Grid.Column="1">Cancel</Button>
</Grid>
Yes, it is also possible to reduce number of Grids to 1, but I see no point in it. Also one can use StackPanel instead of outer Grid.
"The lightest markup" phrase can be interpreted differently. The lightest for developer is the most simple and clear. The lightest for computer is the fastest to initialize and render. As for the given case, the difference is really in 1 extra layout container. This really is not the case to make optimisations
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock grid.row=1 grid.column=0 text="user name" />
<TextBlock grid.row=1 grid.column=1 text="password" />
<TextBox grid.row=2 grid.column=0 />
<TextBox grid.row=2 grid.column=1 />
<Button grid.row=3 grid.column=0 text="OK" />
<Button grid.row=3 grid.column=1 text="Cancel" />
</Grid>
For my applications I like to use ChildWindow. Then on every page I can validate if the user is authetified and pop the child window if that is not the case. This is also nice use bookmarks if you are using the navigation type of project within silverlight.
<toolkit:BusyIndicator IsBusy="False" Name="LoginBusy" >
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="189*" />
<ColumnDefinition Width="189*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="65*" />
<RowDefinition Height="32" />
<RowDefinition Height="32" />
<RowDefinition Height="26*" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="4" Grid.Column="1" TabIndex="3" />
<sdk:Label Grid.Row="1" Name="label1" HorizontalAlignment="Right" Content="Username" Margin="4" />
<sdk:Label Grid.Row="2" Name="label2" HorizontalAlignment="Right" Content="Password" Margin="4" />
<TextBox Grid.Column="1" Grid.Row="1" Name="Username" Margin="4" Text="{Binding Username,Mode=TwoWay}" TextChanged="TextInserted" TabIndex="1" />
<PasswordBox Grid.Column="1" Grid.Row="2" Name="Password" Margin="4" Password="{Binding Password,Mode=TwoWay}" PasswordChanged="TextInserted" TabIndex="2" />
<TextBlock Grid.Column="1" Grid.Row="3" Height="37" HorizontalAlignment="Left" Visibility="Collapsed" Margin="19,13,0,0" Name="ErrorBlock" Text="Authentication Failed." VerticalAlignment="Top" Width="161" Foreground="Red" FontWeight="Bold" />
<Button Grid.Row="4" Height="23" HorizontalAlignment="Left" Margin="46,4,0,0" Visibility="Collapsed" Name="button1" Content="CANCEL" VerticalAlignment="Top" Width="75" Click="CancelButton_Click" IsTabStop="False" />
<Image Name="image1" Stretch="Fill" Source="Images/logo.png" />
</Grid>
</toolkit:BusyIndicator>
This is the content of my child window without the header bits. Notice that I bind directly to a user object which implements the InotifyPropertyChanged. Also while the web service performs the validation I enable the busy indicator so the user sees his request is being processes.
Cheers,
I'm just beginning on figuring out what works best for layout/data display in XAML (WPF), and don't have the intuition yet of what controls, etc work well in certain situations.
Nothing needs to be sorted or filtered, columns and rows are static
Would using a datagrid or some combination of stackpanels/listboxes be best?
I see the "tricky" parts as being adding the "skew adjusted" sub-heading and the separating lines between some of the columns, what would be some suggestions to add these?
I would actually use the standard Grid (not the DataGrid). It seems ankward at the beginning but after you learn how to use it, you're gonna use it everywhere! :)
Here is an example to display your data (its not complete but you see the point):
<Grid x:Name="grdData" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
<ColumnDefinition Width="Auto" MinWidth="50" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock FontWeight="Bold" FontSize="14" Padding="10">Annualized Statistics</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="1">1Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="2">2Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="3">3Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="4">4Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="5">5Yr</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="6">1st Half</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="7">2nd Half</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="8">Incept</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">Return</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="1">(4.81)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="2">(2.25)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="3">1.01</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="4">4.30</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="5">(0.61)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="6">(18.75)</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="7">5.06</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="8">(7.48)</TextBlock>
<Rectangle Grid.Column="5" Grid.Row="1" Grid.RowSpan="5" Fill="Black" Width="1" HorizontalAlignment="Right" />
<Rectangle Grid.Column="7" Grid.Row="1" Grid.RowSpan="5" Fill="Black" Width="1" HorizontalAlignment="Right" />
</Grid>
Is there any way to change the style of gridlines in wpf grid?
I need to divide grid into 4 cells. To do it I used RowDefinitions and ColumnDefinitions. However I need user to distinguish which cell is which, that's why I need to change the color of the gridlines.
It depends on the look you are going for. In WPF, there are different ways to do almost anything. Here are a couple of the easier ones.
The easiest way is to set ShowGridlines="True":
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5"
ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0"
Grid.Row="0"
Text="(0,0)" />
<TextBlock Grid.Column="1"
Grid.Row="0"
Text="(1,0)" />
<TextBlock Grid.Column="0"
Grid.Row="1"
Text="(0,1)" />
<TextBlock Grid.Column="1"
Grid.Row="1"
Text="(1,0)" />
</Grid>
That gives you grid something like:
You can also use a Rectangle in each cell of the grid to get different effects. Here, the Fill is transparent and the Stroke is Blue:
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0"
Grid.Row="0"
Stroke="Blue"
Fill="Transparent" />
<TextBlock Grid.Column="0"
Grid.Row="0"
Text="(0,0)" />
<Rectangle Grid.Column="1"
Grid.Row="0"
Stroke="Blue"
Fill="Transparent" />
<TextBlock Grid.Column="1"
Grid.Row="0"
Text="(1,0)" />
<Rectangle Grid.Column="0"
Grid.Row="1"
Stroke="Blue"
Fill="Transparent" />
<TextBlock Grid.Column="0"
Grid.Row="1"
Text="(0,1)" />
<Rectangle Grid.Column="1"
Grid.Row="1"
Stroke="Blue"
Fill="Transparent" />
<TextBlock Grid.Column="1"
Grid.Row="1"
Text="(1,0)" />
</Grid>
That produces this:
Alternatively, you can fill the Rectangles and not give them a Stroke:
<Grid HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0"
Grid.Row="0"
Fill="LightBlue" />
<TextBlock Grid.Column="0"
Grid.Row="0"
Text="(0,0)" />
<Rectangle Grid.Column="1"
Grid.Row="0"
Fill="LightYellow" />
<TextBlock Grid.Column="1"
Grid.Row="0"
Text="(1,0)" />
<Rectangle Grid.Column="0"
Grid.Row="1"
Fill="LightYellow" />
<TextBlock Grid.Column="0"
Grid.Row="1"
Text="(0,1)" />
<Rectangle Grid.Column="1"
Grid.Row="1"
Fill="LightBlue" />
<TextBlock Grid.Column="1"
Grid.Row="1"
Text="(1,0)" />
</Grid>
That can, for instance, give a checkerboard pattern:
This is by no means a comprehensive answer - you could probably fill a book. It was just meant to show that there are many ways to do what you are asking, and that there are some pretty quick and easy solutions if that's all you need.