简体   繁体   English

在wpf中绑定不起作用,看不到为什么

[英]binding in wpf doesn't work, can't see why

I have a wpf app I'm using some xaml code that should let me view pdf files, I just started to use data biding and don't figure way this not works for me. 我有一个wpf应用程序,正在使用一些xaml代码,该代码应允许我查看pdf文件,我才刚刚开始使用数据出价,并且不知道这种方式对我不起作用。

here m XAML: 在XAML中:

<Grid>
<telerik:RadPdfViewerToolBar RadPdfViewer="{Binding ElementName=pdfViewer, Mode=OneTime}" SignaturePanel="{Binding ElementName=signaturePanel, Mode=OneTime}"/>
<telerik:SignaturePanel x:Name="signaturePanel" PdfViewer="{Binding ElementName=pdfViewer, Mode=OneWay}" Grid.Row="1"/>
<telerik:RadPdfViewer x:Name="pdfViewer" DocumentSource="{Binding Path=PathOfPdf, Mode=TwoWay}"  DataContext="{Binding CommandDescriptors, ElementName=pdfViewer}" telerik:RadPdfViewerAttachedComponents.RegisterSignSignatureDialog="True" telerik:RadPdfViewerAttachedComponents.RegisterFindDialog="True" Grid.Row="2" telerik:RadPdfViewerAttachedComponents.RegisterSignaturePropertiesDialog="True" telerik:RadPdfViewerAttachedComponents.RegisterContextMenu="True"/>
<Grid>

And here code behind: 这是后面的代码:

public partial class Page2 : Page, INotifyPropertyChanged
{
public Page2()
    {
        InitializeComponent();
        DataContext = this;
     }  

private string _pathOfPdf= @"D:\MyFile.pdf";

    public string PathOfPdf
    {
        get{ return _pathOfPdf; }
        set{
            if (_pathOfPdf != value)
            {
                _pathOfPdf = value;
                OnPropertyChanged();
            }
        }

    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }   
}

If I'm not using Biding it works fine. 如果我不使用Biding,则效果很好。 I if I do(on XAML): 如果可以(在XAML上),我会:

DataContext="D:\\MyFile.pdf" it shows the pdf DataContext="D:\\MyFile.pdf"它显示了pdf

You need to either set the DataContext of the control or the source of the binding to the Page where the source property is defined: 您需要将控件的DataContext或绑定的源设置为定义了source属性的Page

<telerik:RadPdfViewer x:Name="pdfViewer"
                      DocumentSource="{Binding Path=PathOfPdf, RelativeSource={RelativeSource AncestorType=Page}}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM