アプリケーションに問題があります。カスタム プロパティを変更した後、UI が正しく更新されませんDisplayMemberBinding="{Binding property}"
。
XAML:
<ListView x:Name="downloadList" HorizontalAlignment="Left" Height="293" Margin="0,126,0,0" VerticalAlignment="Top" Width="810" Grid.IsSharedSizeScope="True" MouseDoubleClick="DownloadList_MouseDoubleClick">
<ListView.View>
<GridView x:Name="DownloadGridView">
<GridViewColumn x:Name="c_filename" Header="File name" Width="{Binding Source={x:Static p:Settings.Default}, Path=downloadList_fileName_Width, Mode=TwoWay}" DisplayMemberBinding="{Binding fileName}" />
<GridViewColumn x:Name="c_size" Header="Size" Width="{Binding Source={x:Static p:Settings.Default}, Path=downloadList_size_Width, Mode=TwoWay}" DisplayMemberBinding="{Binding formattedFileSize}" />
<GridViewColumn x:Name="c_downloaded" Header="Downloaded" Width="{Binding Source={x:Static p:Settings.Default}, Path=downloadList_downloaded_Width, Mode=TwoWay}" DisplayMemberBinding="{Binding sizeProgress}" />
<GridViewColumn x:Name="c_status" Header="Status" Width="{Binding Source={x:Static p:Settings.Default}, Path=downloadList_status_Width, Mode=TwoWay}" DisplayMemberBinding="{Binding Status}"/>
</GridView>
</ListView.View>
</ListView>
これは、プロパティを持つ私のカスタム クラスです。
using System;
using System.Runtime.CompilerServices;
using System.Text;
using System.ComponentModel;
namespace DownloadManager
{
public class DownloadItem : INotifyPropertyChanged
{
private string _filepath;
public string filePath
{
get { return _filepath; }
set
{
_filepath = value;
RaisePropertyChanged();
}
}
private int _sizeprogress;
public int sizeProgress
{
get { return _sizeprogress; }
set
{
_sizeprogress = value;
RaisePropertyChanged();
}
}
// and so on...
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(
[CallerMemberName] string caller = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(caller));
}
}
}
}
タイマー:私がやろうとしていることの実際の例を示すために編集されました
System.Windows.Threading.DispatcherTimer updateTimer = new System.Windows.Threading.DispatcherTimer();
updateTimer.Tick += new EventHandler(updateTimer_Tick);
updateTimer.Interval = new TimeSpan(0, 0, 1);
private void updateTimer_Tick(object sender, EventArgs e)
{
foreach (DownloadItem item in downloadList.Items)
{
long BytesReceived = item.filePath.Length;
item.sizeProgress = BytesReceived;
}
}
item.filePath
ダウンロードするファイルのパスを含み、 a を使用しFileStream
て書き込みます。
私の目標は、毎秒ファイルサイズを読み取って表示することです。
問題: UI (この場合は にバインドされた列sizeProgress
) は、最初のティックで 1 回だけ更新され、その後は何も更新されません。アプリは例外なく引き続き実行されます..
そして、何が問題なのか本当にわかりません。
さらに情報/コードが必要な場合は教えてください。ありがとうございました。