English 中文(简体)
对第Wardow号主意见中之六财产具有约束力的有约束力的错误
原标题:Binding error when binding to Width Property of MainView Window

我有一条主文“温德”,他的宽度和高度是Im,试图使其与《法典》的同学相约束。

<Window x:Class="RpP25.MainView"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"     
   xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
   xmlns:themes="http://schemas.actiprosoftware.com/winfx/xaml/themes"
   xmlns:RpWin="clr-namespace:RpP25"
   xmlns:RpWinCmds="clr-namespace:RpP25.Commands"
   xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
   Title="{Binding Path=FileName, Converter={StaticResource WindowTitleNameConverter}}"
   Height="{Binding Path=WindowHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
   Width="{Binding Path=WindowWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
   Icon="images/CobWhite.ico"
   Loaded="Window_Loaded"
   Closing="Window_Closing">

后面的《法典》有其特性,并且还把数据内容用在观点Model MainVM上。

public partial class MainView : Window, INotifyPropertyChanged
{
    // Constant Fields
    private const double windowDefaultWidth_ = 720;
    private const double windowDefaultHeight_ = 400;

    // Private Fields
    private RegistryKey RegKey_;                                // Registry Key to hold Registry Subkey
    private WindowState windowState_ = WindowState.Normal;   // Display State of the MainWindow (Min,Max or Normal)
    private double windowWidth_ = windowDefaultWidth_;    // Width of the MainWindow
    private double windowHeight_ = windowDefaultHeight_;  // Height of the MainWindow

    #region Constructors

    public MainView()
    {
        InitializeComponent();
        DataContext = new MainVM();

        // Get the state of the window and the width/height from the registry
        ReadRegistryValues();

    /// <summary>
    /// Gets the Width of the Window
    /// </summary>
    public double WindowWidth
    {
        get { return windowWidth_; }
        set { windowWidth_ = value; NotifyPropertyChanged("WindowWidth"); }
    }

    /// <summary>
    /// Gets the Height of the Window
    /// </summary>
    public double WindowHeight
    {
        get { return windowHeight_; }
        set { windowHeight_ = value; NotifyPropertyChanged("windowHeight"); }
    }

    ...
}

This window is created from App::OnStartup().

当我操作该守则时,浮标投下产出窗口中的以下错误。

Cannot found sources for binding with reference RelativeSource FindAncestor, AncestorType= System.Cord.Window , Ancestorlevel= 1 . BledExpression:Path=WindowHala; DataItem=null; Target content is MainView (Name= ); Target property is Height (type Double )

www.un.org/Depts/DGACM/index_french.htm

我认为,我理解具有约束力的模式,但我认为我是错误的:

我想,用FindAncestor 来寻找一个窗户,会使它在发现拥有我财产的主要意见窗口之前, look眼树。

Any help would be MUCH appreciated.

问题回答

审判

Width="{Binding Path=WindowWidth, RelativeSource={RelativeSource Self}}"

背后是你窗口的同样内容。 因此,使用自我约束。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签