Skip to content

Instantly share code, notes, and snippets.

@veigr
Created November 25, 2014 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veigr/448239ad2636c4c5f673 to your computer and use it in GitHub Desktop.
Save veigr/448239ad2636c4c5f673 to your computer and use it in GitHub Desktop.
[WPF]GridのRowDefinitionのHeightをWindowのHeightに応じて任意に変化させる的な
using System;
using System.Windows;
using System.Windows.Data;
namespace WpfApplication1
{
public class DoubleToGridLengthConverter : IValueConverter
{
private static readonly GridLengthConverter Conv = new GridLengthConverter();
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Conv.ConvertFrom((double)value < 200 ? "Auto" : "*");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfApplication1="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<wpfApplication1:DoubleToGridLengthConverter x:Key="DoubleToGridLengthConverter"/>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=Height, Converter={StaticResource DoubleToGridLengthConverter}}"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="IndianRed" Height="20"/>
<Border Grid.Row="1" Background="CornflowerBlue"/>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment