켄트 Boogaart는 요소의 크기를 관찰하는 속성 첨부 쓴 :
https://stackoverflow.com/a/1083733/4049478
이 아마 관찰자가 문제 (정말 저렴 솔루션에 적용 MVVM
를 사용하여 최적의 솔루션을하지만, 그럼에도 불구하고 용액) :
public class RowDefinitionObserver {
public static readonly DependencyProperty ObserveRowProperty = DependencyProperty.RegisterAttached(
"ObserveRow",
typeof(bool),
typeof(RowDefinitionObserver),
new FrameworkPropertyMetadata(OnObserveChanged));
public static readonly DependencyProperty ObservedRowHeightProperty = DependencyProperty.RegisterAttached(
"ObservedRowHeight",
typeof(double),
typeof(RowDefinitionObserver));
public static bool GetObserveRow(FrameworkElement frameworkElement) {
return (bool)frameworkElement.GetValue(ObserveRowProperty);
}
public static void SetObserveRow(FrameworkElement frameworkElement, bool observe) {
frameworkElement.SetValue(ObserveRowProperty, observe);
}
public static double GetObservedRowHeight(FrameworkElement frameworkElement) {
return (double)frameworkElement.GetValue(ObservedRowHeightProperty);
}
public static void SetObservedRowHeight(FrameworkElement frameworkElement, double observedHeight) {
frameworkElement.SetValue(ObservedRowHeightProperty, observedHeight);
}
private static void OnObserveChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) {
var frameworkElement = (FrameworkElement)dependencyObject;
if ((bool)e.NewValue) {
frameworkElement.SizeChanged += OnFrameworkElementSizeChanged;
UpdateObservedSizesForFrameworkElement(frameworkElement);
} else {
frameworkElement.SizeChanged -= OnFrameworkElementSizeChanged;
}
}
private static void OnFrameworkElementSizeChanged(object sender, SizeChangedEventArgs e) {
UpdateObservedSizesForFrameworkElement((FrameworkElement)sender);
}
private static void UpdateObservedSizesForFrameworkElement(FrameworkElement frameworkElement) {
Grid g = frameworkElement as Grid;
if (g != null) {
if (g.RowDefinitions.Count > 1) {
SetObservedRowHeight(g, g.RowDefinitions[1].ActualHeight);
}
}
}
}
사용법 :
<Grid attachedProperties:RowDefinitionObserver.ObserveRow="True"
attachedProperties:RowDefinitionObserver.ObservedRowHeight="{Binding RowHeight, Mode=OneWayToSource}"><!--RowHeight is a double Property in your ViewModel-->
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="240"/>
</Grid.RowDefinitions>
<Grid/>
<Grid Grid.Row="1" Background="Red"/>
<Grid Grid.Row="2"/>
</Grid>
은 적응 당신이 RowDefinition 뒤에 코드에서
의 인덱스에 대한 DP를 추가해야 만들려면? XAML에서? 귀하의 ViewModel에서? 일부 코드 게시 – JPVenson
MSDN의 [RowDefinition 속성] (http://msdn.microsoft.com/en-us/library/system.windows.controls.rowdefinition_properties.aspx) 목록을 확인하십시오. 거기에 나열된 첫 번째 것이 도움이 될 수 있습니다. – Clemens
당신은 [this one] (http://stackoverflow.com/a/1083733/4049478) – nkoniishvt