Created
November 25, 2014 05:58
-
-
Save veigr/448239ad2636c4c5f673 to your computer and use it in GitHub Desktop.
[WPF]GridのRowDefinitionのHeightをWindowのHeightに応じて任意に変化させる的な
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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