Click here to Skip to main content
15,885,365 members
Home / Discussions / WPF
   

WPF

 
QuestionHow do I center a Silverlight page on a browser at all times? Pin
Jun Du4-Mar-10 6:04
Jun Du4-Mar-10 6:04 
AnswerRe: How do I center a Silverlight page on a browser at all times? Pin
Not Active4-Mar-10 6:26
mentorNot Active4-Mar-10 6:26 
GeneralRe: How do I center a Silverlight page on a browser at all times? Pin
Jun Du4-Mar-10 6:29
Jun Du4-Mar-10 6:29 
AnswerRe: How do I center a Silverlight page on a browser at all times? Pin
Abhinav S14-Mar-10 21:15
Abhinav S14-Mar-10 21:15 
QuestionText for geometryModel3d should not rotate in wpf Pin
Ramkumar19883-Mar-10 20:27
Ramkumar19883-Mar-10 20:27 
QuestionLoading Image at runtime foe control library. Pin
Anu_Bala3-Mar-10 18:38
Anu_Bala3-Mar-10 18:38 
QuestionWPF Nested Grid Sizing Question Pin
Kennebel3-Mar-10 4:23
Kennebel3-Mar-10 4:23 
AnswerRe: WPF Nested Grid Sizing Question Pin
AspDotNetDev3-Mar-10 21:49
protectorAspDotNetDev3-Mar-10 21:49 
I'm not sure I fully understood your question, but this seems to do what you want (though it is admittedly complicated):

XAML:
XML
<Window x:Class="QuickWPFTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="500" Name="MyWin" Loaded="MyWin_Loaded">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"></ColumnDefinition>
            <ColumnDefinition MinWidth="50"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" Background="Black"></Grid>
        <Grid Grid.Column="1" HorizontalAlignment="Stretch" Name="OuterGrid" SizeChanged="OuterGrid_SizeChanged">
            <ScrollViewer HorizontalScrollBarVisibility="Auto"
                        VerticalScrollBarVisibility="Disabled">
                <Grid HorizontalAlignment="Stretch" Name="InnerGrid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MaxWidth="{Binding MaxColumnWidth, ElementName=MyWin}"
                            Name="FirstColumn" MinWidth="100" Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="3"></ColumnDefinition>
                        <ColumnDefinition MaxWidth="100" MinWidth="100"></ColumnDefinition>
                        <!-- This takes up the unused space to the right of the other columns. -->
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="0">
                        <ScrollViewer VerticalScrollBarVisibility="Auto">
                            <ListView Margin="0,0" Name="listView1" SelectionMode="Single" />
                        </ScrollViewer>
                    </Grid>
                    <GridSplitter Background="Red" Grid.Column="1" Grid.Row="0"
                        Height="Auto" Width="Auto" HorizontalAlignment="Stretch"
                        VerticalAlignment="Stretch" />
                    <Grid Grid.Column="2">
                        <ScrollViewer VerticalScrollBarVisibility="Auto">
                            <ListView Margin="0,0" Name="listView2" SelectionMode="Single" />
                        </ScrollViewer>
                    </Grid>
                </Grid>
            </ScrollViewer>
        </Grid>
    </Grid>
</Window>

C#:
C#
using System.ComponentModel;
using System.Windows;

namespace QuickWPFTest
{

	/// <summary>
	/// Interaction logic.
	/// </summary>
	public partial class Window1 : Window, INotifyPropertyChanged
	{

		// Constructor.
		public Window1()
		{
			InitializeComponent();
		}


		// When the window loads, change the width of the column.
		// Leave it at "*" would prevent resizing with the grid splitter.
		private void MyWin_Loaded(object sender, RoutedEventArgs e)
		{
			ChangeWidth();
		}


		// The outer grid got smaller or larger.
		private void OuterGrid_SizeChanged(object sender, SizeChangedEventArgs e)
		{

			// The maximum column width is based on the outer grid's width.
			// Since the outer grid width changed, the maximum column width did too.
			OnPropertyChanged("MaxColumnWidth");


			// When the outer grid is smaller than the inner, the inner width gets changed.
			if (InnerGrid.ActualWidth > OuterGrid.ActualWidth)
			{

				// Try commenting out this code block to see the different behavior.
				ChangeWidth();

			}

		}


		// Change the width of the column.
		private void ChangeWidth()
		{
			double diff = InnerGrid.ActualWidth - OuterGrid.ActualWidth;
			double newWidth = FirstColumn.ActualWidth - diff;
			if (newWidth < 0) newWidth = 0;
			FirstColumn.Width = new GridLength(newWidth);
		}


		// The column width may be no larger than the outer grid's width minus 103.
		public double MaxColumnWidth
		{
			get
			{
				return OuterGrid.ActualWidth - 100 - 3;
			}
		}

		
		// One of the properties changed.
		public event PropertyChangedEventHandler PropertyChanged;

		
		// Convenience method to raise property changed event.
		private void OnPropertyChanged(string name)
		{
			if (this.PropertyChanged != null)
			{
				this.PropertyChanged(this, new PropertyChangedEventArgs(name));
			}
		}

	}

}

GeneralRe: WPF Nested Grid Sizing Question Pin
Kennebel5-Mar-10 9:04
Kennebel5-Mar-10 9:04 
GeneralRe: WPF Nested Grid Sizing Question Pin
AspDotNetDev5-Mar-10 9:22
protectorAspDotNetDev5-Mar-10 9:22 
QuestionResizing and realigning the contents of a WPF windows form Pin
sameercodes3-Mar-10 4:20
sameercodes3-Mar-10 4:20 
AnswerRe: Resizing and realigning the contents of a WPF windows form Pin
April Fans3-Mar-10 17:47
April Fans3-Mar-10 17:47 
QuestionProperty editing not available for Blend-generated XAML... Pin
Jun Du2-Mar-10 2:14
Jun Du2-Mar-10 2:14 
AnswerRe: Property editing not available for Blend-generated XAML... Pin
April Fans3-Mar-10 14:49
April Fans3-Mar-10 14:49 
AnswerRe: Property editing not available for Blend-generated XAML... Pin
fred_17-Mar-10 9:46
fred_17-Mar-10 9:46 
QuestionHow do I handle both hover and click events on a button control? Pin
Jun Du1-Mar-10 11:19
Jun Du1-Mar-10 11:19 
AnswerRe: How do I handle both hover and click events on a button control? Pin
April Fans1-Mar-10 15:47
April Fans1-Mar-10 15:47 
AnswerRe: How do I handle both hover and click events on a button control? Pin
Abhinav S1-Mar-10 22:24
Abhinav S1-Mar-10 22:24 
QuestionFindResource method in WPF Pin
Ahamed Azeem1-Mar-10 1:57
Ahamed Azeem1-Mar-10 1:57 
AnswerRe: FindResource method in WPF Pin
fjparisIII1-Mar-10 7:30
fjparisIII1-Mar-10 7:30 
Questionanimation Pin
Ahamed Azeem28-Feb-10 19:50
Ahamed Azeem28-Feb-10 19:50 
AnswerRe: animation Pin
GomathiR28-Feb-10 21:52
GomathiR28-Feb-10 21:52 
GeneralRe: animation Pin
Ahamed Azeem1-Mar-10 1:23
Ahamed Azeem1-Mar-10 1:23 
GeneralRe: animation Pin
Ahamed Azeem1-Mar-10 1:26
Ahamed Azeem1-Mar-10 1:26 
AnswerRe: animation Pin
Pete O'Hanlon28-Feb-10 22:51
mvePete O'Hanlon28-Feb-10 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.