Ответ 1
Как отмечено в разделе Заметки о миграции на странице Setter.Value на MSDN, UWP/Windows Runtime не поддерживает привязки в стиле сеттеры.
Windows Presentation Foundation (WPF) и Microsoft Silverlight поддерживала возможность использования выражения Binding для предоставления значения для сеттера в стиле. Windows Runtime не поддерживает привязку использование для Setter.Value(привязка не будет оцениваться, и сеттер никакого эффекта, вы не получите ошибок, но вы не получите желаемого результата или). Когда вы конвертируете стили XAML из WPF или Silverlight XAML, замените любые выражения привязки выражения строками или объектами, которые устанавливают значения или рефакторинг значений в качестве общей разметки {StaticResource} значения расширения, а не полученные значения привязки.
Обходной путь может быть вспомогательным классом со связанными свойствами для исходных путей привязок. Он создает привязки в коде позади в PropertyChangedCallback свойства helper:
public class BindingHelper
{
public static readonly DependencyProperty GridColumnBindingPathProperty =
DependencyProperty.RegisterAttached(
"GridColumnBindingPath", typeof(string), typeof(BindingHelper),
new PropertyMetadata(null, GridBindingPathPropertyChanged));
public static readonly DependencyProperty GridRowBindingPathProperty =
DependencyProperty.RegisterAttached(
"GridRowBindingPath", typeof(string), typeof(BindingHelper),
new PropertyMetadata(null, GridBindingPathPropertyChanged));
public static string GetGridColumnBindingPath(DependencyObject obj)
{
return (string)obj.GetValue(GridColumnBindingPathProperty);
}
public static void SetGridColumnBindingPath(DependencyObject obj, string value)
{
obj.SetValue(GridColumnBindingPathProperty, value);
}
public static string GetGridRowBindingPath(DependencyObject obj)
{
return (string)obj.GetValue(GridRowBindingPathProperty);
}
public static void SetGridRowBindingPath(DependencyObject obj, string value)
{
obj.SetValue(GridRowBindingPathProperty, value);
}
private static void GridBindingPathPropertyChanged(
DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var propertyPath = e.NewValue as string;
if (propertyPath != null)
{
var gridProperty =
e.Property == GridColumnBindingPathProperty
? Grid.ColumnProperty
: Grid.RowProperty;
BindingOperations.SetBinding(
obj,
gridProperty,
new Binding { Path = new PropertyPath(propertyPath) });
}
}
}
Вы бы использовали их в XAML следующим образом:
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="local:BindingHelper.GridColumnBindingPath" Value="Level"/>
<Setter Property="local:BindingHelper.GridRowBindingPath" Value="Row"/>
</Style>
</ItemsControl.ItemContainerStyle>
Для простого обходного пути для абсолютного позиционирования (т.е. связывания свойств Canvas.Left
и canvas.Top
) см. этот ответ.