|
Put the grid splitter inside its own column:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="64*" />
<RowDefinition Height="310*" />
<RowDefinition Height="88*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190.667*" />
<ColumnDefinition Width="2" />
<ColumnDefinition Width="387.333*" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2"
CornerRadius="6"
BorderThickness="1"
BorderBrush="Gray"
Background="LightGray"
Margin="6 5 6 5">
<TextBlock Text="Select a font from the list below. You can change the text by typing in the region at the bottom."
FontSize="14" TextWrapping="Wrap" VerticalAlignment="Top"/>
</Border>
<ListBox x:Name="FontList"
Grid.Row="1"
Grid.RowSpan="2"
ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="6,5,6,5"/>
<GridSplitter Grid.Row="1" Grid.RowSpan="2" Grid.Column="1"
Width="2"
Background="Gray"
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext" Margin="0,1,0,5" HorizontalAlignment="Stretch" />
<TextBox x:Name="SampleText"
Grid.Row="2"
Grid.Column="2"
MinLines="4"
Margin="6 5 6 5"
TextWrapping="Wrap"
ToolTip="Type here to change the preview text">
The quick brown fox jumps over the lazy dog. </TextBox>
<GridSplitter Grid.Row="1"
Grid.Column="1"
Width="2"
Background="Gray"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Rows"/>
<StackPanel Grid.Row="1"
Grid.Column="2"
Margin="6 5 6 5">
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="10"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="16"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="24"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="32"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
</StackPanel>
</Grid>
|
|
|
|
|
Also, it looks like you had two splitters. I took one out. If you want a splitter for rows too, give that splitter it's own row. This shows just the column splitter:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="64*" />
<RowDefinition Height="310*" />
<RowDefinition Height="88*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190.667*" />
<ColumnDefinition Width="2" />
<ColumnDefinition Width="387.333*" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2"
CornerRadius="6"
BorderThickness="1"
BorderBrush="Gray"
Background="LightGray"
Margin="6 5 6 5">
<TextBlock Text="Select a font from the list below. You can change the text by typing in the region at the bottom."
FontSize="14" TextWrapping="Wrap" VerticalAlignment="Top"/>
</Border>
<ListBox x:Name="FontList"
Grid.Row="1"
Grid.RowSpan="2"
ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="6,5,6,5"/>
<TextBox x:Name="SampleText"
Grid.Row="2"
Grid.Column="2"
MinLines="4"
Margin="6 5 6 5"
TextWrapping="Wrap"
ToolTip="Type here to change the preview text">
The quick brown fox jumps over the lazy dog. </TextBox>
<GridSplitter Grid.Row="1"
Grid.Column="1"
Grid.RowSpan="2"
Width="2"
Background="Gray"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Columns"/>
<StackPanel Grid.Row="1"
Grid.Column="2"
Margin="6 5 6 5">
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="10"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="16"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="24"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="32"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
</StackPanel>
</Grid>
|
|
|
|
|
Got it. Thank you very much
|
|
|
|
|
I'm working with an established and growing commercial software development firm in Philadelphia. They are in need of a very strong C# WPF developer to join their Windows product development team. Agile/ TDD environment. Client is open to contract or full time. The position would be on-site in Philly. If you are interested in more info, I can be reached at ben.cadbury@modis.com. Thanks!
|
|
|
|
|
Please use the jobs forum.
It's time for a new signature.
|
|
|
|
|
Hello,
I want to have a Grid with zero "width" (alas you can't see it) being resized as an effect when I click enter in my program. (Kind of like this: http://www.bestbefore.ro[^] --> click on one of the links and see how the "lines" resize)
However, I have no clue as how to do it. No sample code whatsoever. I would like it to be done via code, or atleast be able to start the effect through code.
Here is my project and source code: http://www.sendspace.com/file/k2vus0[^]
I realize it's a kind of lame project name, but it's a school task. (And I'm not used to WPF, so the "I'm the expert" doesn't really apply :P)
Thanks,
Theo
|
|
|
|
|
What you want is a storyboard, which basically allows you to animate by transitioning a property from one value to another. For example, you can make a storyboard that transitions from the color red to the color blue, gradually. There is also the DoubleAnimation you can use in a storyboard, which allows you to transition from, say, the value 0 to the value 1.5, gradually. You'd want to use this DoubleAnimation storyboard to modify a width.
If you want to do more complex grid animations (e.g., by resizing specific columns), you're gonna want to read this article. In fact, you might want to start by reading that article. It gives a good introduction to storyboards and animations.
|
|
|
|
|
Hello,
Thanks for the links. However now I am stuck. This code doesn't do anything - my lines just keeps not being visible.
double left = horizontalLineContainer.Margin.Left;
double top = horizontalLineContainer.Margin.Top;
double right = horizontalLineContainer.Margin.Right;
double bottom = horizontalLineContainer.Margin.Bottom;
horizontalLineContainer.Margin = new Thickness(left, top, left, bottom);
ThicknessAnimation animation = new ThicknessAnimation();
animation.Duration = new TimeSpan(0, 0, 2);
animation.From = horizontalLineContainer.Margin;
animation.To = new Thickness(left, top, right, bottom);
Storyboard.SetTarget(animation, horizontalLineContainer);
Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.MarginProperty));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin();
Thanks,
Theo
|
|
|
|
|
OK, so I got it to display. It seems it does the animation, but it's extremely fast, no matter what TimeSpan I enter, be it 2 or 20000 seconds. Here's my code:
double left = horizontalLineContainer.Margin.Left;
double top = horizontalLineContainer.Margin.Top;
double right = horizontalLineContainer.Margin.Right;
double bottom = horizontalLineContainer.Margin.Bottom;
horizontalLineContainer.Margin = new Thickness(left, top, left, bottom);
horizontalLineContainer.Visibility = Visibility.Visible;
ThicknessAnimation animation = new ThicknessAnimation();
animation.Duration = new TimeSpan(0, 0, 20000);
animation.From = horizontalLineContainer.Margin;
animation.To = new Thickness(left, top, right, bottom);
Storyboard.SetTargetName(animation, horizontalLineContainer.Name);
Storyboard.SetTargetProperty(animation, new PropertyPath(Grid.MarginProperty));
Storyboard storyboard = new Storyboard();
storyboard.Children.Add(animation);
storyboard.Begin(horizontalLineContainer);
NOTE: I would like to say that this is very urgent, as this is a school task due monday. Any help is appreciated.
Thanks,
Theo
|
|
|
|
|
I don't see how that works at all. The "From" and "To" are identical.
|
|
|
|
|
Hi Guys,
I've got a MyUserControl i have created for my app. When i click on, or mouse over the MyUserControl, i'd like the events to be raised with the MyUserControl as the OrigionalSource. As they are composite controls, made up of numerous other controls, i get whatever child control was clicked inside MyUserControl.
How do i go about achiving this?
Regards
Tristan
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
AFAIK, you can only get the control for which the event was fired.
Use the VisualTreeHelper's VisualTreeHelper.FindElementsInHostCoordinates method to get all control within the mouse position from where the event was fired.
|
|
|
|
|
You could make them all global (setting a property for the element in XAML, or when you create them in code. At that point, you can subsribe to those events anywhere you want.
I know it's cheating, but it works, and you can't afford to spend a week on this stuff. Right?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi, thanks. that got me thinking, and in the end i implemented an ITarget interface on every control i wanted clicked, and looped through the parent controls until I found an implementor.
Surely there's a better way.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
The "best" way is whatever you can get to work. Remember, your project is late (no matter if it actually is or not).
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Well, that depends on who's maintaining the "best" way :P
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
With a WinForms hyperlink you can set it to only be underliend when the mouse is over it. How can I do this in a WPF hyperlink?
Everything makes sense in someone's mind
|
|
|
|
|
Write a Style for Button like a Hyperlink and do whatever you want to do.
Advantage:
- You got a Hyperlink as you asked for
- You will get more events than a Hyperlink.
|
|
|
|
|
Could you explain how to do that? I'm rather new to WPF.
TIA
Everything makes sense in someone's mind
|
|
|
|
|
Hi
Since I am building the columns from code-behind, I need to attach hyperlink into one of the columns from code behind. And also, I need to add the click event.
How can I do that and its data-binding in code behind? Please advise.
Thanks
AJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
I just did that in our own silverlight app (I assume you're talking about a regular Grid (as opposed to a DataGrid).
I simply created the button and set the Tag property indicating it's purpose (or associated data). This kept me from having to set a unique Name . After the button was created, I subscribed to the Click event (all buttons used the same event method), and then added the button to the appropriate grid column/row.
In the event handler, the Tag object indicated what the button was supposed to do.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I have written a Silverlight 4 application that reads a data stream and interprets it to dynamically create a web page. As part of the design I need to add grids to the page to act as placeholders to mimic the appearance and behaviour of tables. Here I am dynamically creating a grid with [gridCols] number of columns:
Grid LocalGrid = new Grid();
LocalGrid.Width = Double.NaN; // Auto Width and Height
LocalGrid.Height = Double.NaN;
for (int c=1; c <= gridCols; c++) // Add the columns
{ // Add a new column to the grid
LocalGrid.ColumnDefinitions.Add(new ColumnDefinition() { MinWidth = 10.0 });
}
LocalGrid.Background = new SolidColorBrush(Colors.LightGray);
So far, so good. I can now add rows as I need them with:
LocalGrid.RowDefinitions.Add(new RowDefinition() { MinHeight = 15 });
When the grid is fully loaded and formatted I can add it to a placeholder on the web page.
So, question, how can I get at and programmatically alter the properties of the added rows? For example how can I set the background colour of a row to do an alternating-row colour scheme. I have seen examples of using the LoadingRow event, but this grid is not data-bound.
Grid rows do not have properties such as BackColor exposed. I'm guessing that I need to use SetValue but, if so, what are the required parameters and how can I see a list of the dependency properties?
Any help greatly appreciated.
Kind regards
Paul
________________
Eschew Obfuscation
Anon
|
|
|
|
|
I guess you might be adding one or more controls to every row that you create.
Setting the background color of the parent control in every alternate row may help you solve this problem.
This is definitely not an optimal way, but perhaps the only way (for a
Grid control).
Setting alternate row colors for an items control is relatively easier and uses the approach you have mentioned in your post (using LoadingRow).
|
|
|
|
|
Hi,
I have a problem with rotating a WPF UIElement and placing it within a small space.
Consider the following problem:
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="30" Height="100">
<Button Content="This is my button"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="100"
Height="30"
RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<RotateTransform Angle="90" />
</Button.RenderTransform>
</Button>
WPF seems to draw the grid, draw the button (with the sides cut off) and then rotate the button (without sides).
Has anyone encountered this problem before?
Shane
|
|
|
|
|
Try LayoutTransform instead of RenderTransform.
|
|
|
|
|