Xpsを正常に読み込んだC#Wpfプロジェクトがあります。ファイルをドキュメントビューアに追加します。私は、ドキュメントをスクロールするときにページの変化に気づく変数をC#コードに持たせたいと思っています。 これまでのところ私は、XAMLコードのための機能がありますが、次のページにスクロールした場合、それは自動的にページ番号を変更することを、考え出した:WPFドキュメントビューアの通知ページの変更
<DocumentViewer x:Name="viewDocument" HorizontalAlignment="Left" VerticalAlignment="Top" Height="Auto" Grid.Row="0" Grid.Column="0" >
<FixedDocument></FixedDocument>
</DocumentViewer>
<TextBlock Text="{Binding ElementName=viewDocument,Path=MasterPageNumber}" Grid.Row="1"/>
私の最終目標は、ユーザが費やしたSTO pthe時間にあります私は上記の例ではできない私のコード内の変数と現在のページ番号を接続できるようにする必要がある理由です。私はINotifyPropertyChangedを実装しようとしましたが、C#をかなり新しくしており、エラーを見つけることができません。変数を最初のページに設定しますが、その後は更新されません。
は、これは私のビューモデルである:
using System; using System.ComponentModel;
namespace Tfidf_PdfOnly {
public class MainViewModel : INotifyPropertyChanged
{
private int _myLabel;
public int MyLabel
{
get
{
return this._myLabel;
}
set
{
this._myLabel = value;
NotifyPropertyChanged("MyLabel");
}
}
public MainViewModel()
{
_myLabel = 55;
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
、これが私のDocument_Viewer.xaml.csが、それは私がUI上のラベルにそれをバインド動作するかどうかを確認するには
XpsDocument document1 = new XpsDocument(path, System.IO.FileAccess.Read);
//load the file into the viewer
viewDocument.Document = document1.GetFixedDocumentSequence();
MainViewModel vm = new MainViewModel();
this.DataContext = vm;
vm.MyLabel = viewDocument.MasterPageNumber;
ファイルにあります。
<DocumentViewer x:Name="viewDocument" HorizontalAlignment="Left" VerticalAlignment="Top" Height="Auto" Grid.Row="0" Grid.Column="0" >
<FixedDocument></FixedDocument>
</DocumentViewer>
<TextBlock Text="{Binding MyLabel, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" Grid.Row="1" HorizontalAlignment="Right"/>
私の質問がはっきりしていることを願っています。