When I try to bind the attached property, then there is compilation error reported. Why is that?
...
<Canvas Canvas.Left="{Binding LeftPanel.X}"
Canvas.Top="{Binding LeftPanel.Y}"
Background="Red" />
...
Error:
Severity Code Description Project File Line Suppression State
Error C#/XAML for HTML5: XamlPreprocessor (pass 2) failed: Property "Canvas" not found in type "Windows.UI.Xaml.Controls.Canvas". Note: the XAML editor sometimes raises errors that are misleading. To see only real non-misleading errors, make sure to close all the XAML editor windows/tabs before compiling. portApp1 C:\Visual Studio 2015\Projects\portApp1\portApp1\Views\MainPage.xaml 12
More details:
Code: Select all
<Page x:Class="portApp1.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:portApp1"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
DataContext="{Binding MainViewModel, Source={StaticResource Locator}}"
mc:Ignorable="d">
<Grid Background="#FF00C000">
<Canvas>
<Canvas Canvas.Left="{Binding LeftPanel.X}"
Canvas.Top="{Binding LeftPanel.Y}"
Width="{Binding LeftPanel.Width}"
Height="{Binding LeftPanel.Height}"
Background="Red" />
</Canvas>
</Grid>
</Page>
Code: Select all
class MainViewModel : ViewModelBase
{
LayoutManager _LayoutManager = new LayoutManager();
public Rect LeftPanel
{
get { return _LayoutManager.Left; }
}
}
Code: Select all
class LayoutManager : ViewModels.ViewModelBase
{
public Rect Left
{
get
{
var rectangle = new Rect
{
Width = Screen.Width * 0.25f,
Height = Screen.Height
};
return rectangle;
}
}
public Rect Screen
{
get { return Get<Rect>(); }
set
{
Set(value);
}
}
}