ObservableCollectionのBitmapSourceオブジェクトを取得して、WPFフォーム上の画像の束にバインドして、画像が表示されないようにしようとしています...画像がプロパティにロードされていることを確認しました。私のバインディングは間違っているはずです.....どのようにバインディングパスをコード化する必要がありますか?私は、それぞれのイメージをさまざまなオブジェクトに束縛していましたが、リストを使用するほうがはるかに優れているので、バインドしたいと思います。......画像コントロールを観察可能なコレクションにバインドする
テキストボックスにProgramPathプロパティが正しく表示されます。ちょうどイメージソースは
XAMLを拘束取得することはできません - グリッドの中に私はお互い
<TextBox HorizontalAlignment="Stretch" Margin="24,2,2,2" Name="TextBoxA" VerticalAlignment="Stretch"
Width="664" >
<Binding Path=".[0].ProgramPath" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:ExternalProgramValidator/>
</Binding.ValidationRules>
</Binding>
</TextBox>
<TextBox Grid.Row="1" HorizontalAlignment="Stretch" Margin="24,2,2,2" Name="TextBoxB" VerticalAlignment="Stretch" Width="664" >
<Binding Path=".[1].ProgramPath" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<local:ExternalProgramValidator/>
</Binding.ValidationRules>
</Binding>
</TextBox>
<Image Height="16 " HorizontalAlignment="Left"
Margin="4" Name="ImageA" Stretch="Fill" VerticalAlignment="Center" Width="16"
Source="{Binding Path=.[0].ProgramImage, UpdateSourceTrigger=PropertyChanged}">
</Image>
<Image Grid.Row="1" Height="16 " HorizontalAlignment="Left"
Margin="4" Name="ImageB" Stretch="Fill" VerticalAlignment="Center" Width="16"
Source="{Binding Path=.[0].ProgramImage, UpdateSourceTrigger=PropertyChanged}"/>
の隣のテキストボックスや画像の数を持っているそして、私はこの
public class ExternalProgramsWindowData : INotifyPropertyChanged
{
private BitmapSource _ExtractPathImage(string fullPath)
{
BitmapSource returnedImage = null;
string pathForImage = string.Empty;
string[] s = fullPath.Split(new string[] { ".exe" }, StringSplitOptions.None);
if (s[0] != null)
{
pathForImage = s[0] + ".exe";
}
if (!string.IsNullOrWhiteSpace(pathForImage))
{
System.Drawing.Icon icon = IconExtractor.GetIcon(pathForImage, true);
returnedImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
icon.Handle,
System.Windows.Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
}
return returnedImage;
}
/// <summary>
/// A
/// </summary>
private string _programPath;
public string ProgramPath
{
get { return _programPath; }
set
{
_programPath = value;
Notify("ProgramPath");
ProgramImage = _ExtractPathImage(_programPath);
}
}
private BitmapSource _programImage;
public BitmapSource ProgramImage
{
get { return _programImage; }
set
{
_programImage = value;
Notify("ProgramImage");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void Notify(string propName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
#endregion
}
のような公共のクラスを持っていますメインウィンドウクラスで210
私は、これらのクラスのコレクションにグリッドをバインドする
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class ExternalProgramsWindow : Window
{
public ObservableCollection<ExternalProgramsWindowData> WindowDataList { get; set; }
WindowDataList = new ObservableCollection<ExternalProgramsWindowData>();
ExternalPrograms_ExternalProgramsGrid.DataContext = WindowDataList;
オブジェクトそれから私は、コレクションをロードし、そしてProgramPathプロパティが設定され、それが画像に設定されますProgramImageを(設定トリガされます正しく、しかし、ウィンドウに画像が表示されない)
foreach (ExternalProgram program in externalProgramList)
{
ExternalProgramsWindowData oExternalProgramsWindowData = new ExternalProgramsWindowData();
oExternalProgramsWindowData.ProgramPath = program.Path + " " + program.Arguments;
WindowDataList.Add(oExternalProgramsWindowData);
[バインディングエラー](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpfを-or-silverlight-application.aspx)? –
更なるコードで更新された質問を見る...... – theDoke
あなたはまだバインディングエラーについて言及していませんし、書式もまた恐ろしいものです:( –