Click here to Skip to main content
15,895,812 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Another MVVM questionn regarding updating info on other controls? Pin
Pete O'Hanlon21-Jul-12 8:06
mvePete O'Hanlon21-Jul-12 8:06 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Christian Amado21-Jul-12 11:45
professionalChristian Amado21-Jul-12 11:45 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Alisaunder21-Jul-12 12:30
Alisaunder21-Jul-12 12:30 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Mycroft Holmes21-Jul-12 13:52
professionalMycroft Holmes21-Jul-12 13:52 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Alisaunder21-Jul-12 14:59
Alisaunder21-Jul-12 14:59 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Mycroft Holmes21-Jul-12 16:14
professionalMycroft Holmes21-Jul-12 16:14 
GeneralRe: Another MVVM questionn regarding updating info on other controls? Pin
Pete O'Hanlon22-Jul-12 21:52
mvePete O'Hanlon22-Jul-12 21:52 
QuestionAdding datagrid cell images at runtime doesn't appear in cell Pin
alleyes20-Jul-12 8:40
professionalalleyes20-Jul-12 8:40 
I'm trying to add images to a column in a WPF datagrid which are read from a folder and not added as a static resource. The datagrid shows the path to the image in debug but the cell is empty.

XAML:
XML
<DataGrid
    Name="dgDevices"
    AutoGenerateColumns="False"
    CanUserAddRows="False"
    ItemsSource="{Binding Scanners}"
    SelectionChanged="dgDevices_SelectionChanged">            
    <DataGrid.Columns>
        <DataGridTemplateColumn Header="Device Image">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Name="imgScanner" Source="{Binding Path=ImageFile}" Height="100" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTemplateColumn Header="Details" Width="*">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock TextWrapping="Wrap">
                        <TextBlock Text="{Binding Path=FriendlyName}"/>
                        <Hyperlink NavigateUri="{Binding Path=URL}" RequestNavigate="Hyperlink_RequestNavigate">
                            <TextBlock Text="{Binding Path=URL}"/>
                        </Hyperlink>
                    </TextBlock>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>


Code that describes the objects for the datagrid:
C#
public class Scanners : INotifyPropertyChanged
{
#region dongleNum related info

    private UInt32 thisIPAddress;
    public UInt32 IPAddress
    {
        get { return thisIPAddress; }
        set { thisIPAddress = value; NotifyPropertyChanged("IPAddress"); }
    }

    private UInt64 thisMACAddress;
    public UInt64 MACAddress
    {
        get { return thisMACAddress; }
        set { thisMACAddress = value; NotifyPropertyChanged("MACAddress"); }
    }

#endregion

#region Device related info

    private string thisPortName;
    public string PortName
    {
        get { return thisPortName; }
        set { thisPortName = value; NotifyPropertyChanged("PortName"); }
    }

#endregion

#region Driver related info

    private string thisDeviceGuid;
    public string DeviceGuid
    {
        get { return thisDeviceGuid; }
        set { thisDeviceGuid = value; NotifyPropertyChanged("DeviceGuid"); }
    }

#endregion

#region Presentation related info

    private string thisImageFile;
    public string ImageFile
    {
        get { return thisImageFile; }
        set { thisImageFile = value; NotifyPropertyChanged("ImageFile"); }
    }

    private string thisFriendlyName;
    public string FriendlyName
    {
        get { return thisFriendlyName; }
        set { thisFriendlyName = value; NotifyPropertyChanged("FriendlyName"); }
    }

    private Uri thisURL;
    public Uri URL
    {
        get { return thisURL; }
        set { thisURL = value; NotifyPropertyChanged("URL"); }
    }

    #endregion

#region Constructors

    public Scanners(string newFriendlyName, string newImageFile)
    {
        FriendlyName = newFriendlyName;
        ImageFile = newImageFile;
    }

    public Scanners(sxWrapper.sxDeviceInfo DeviceInfo, string newFriendlyName, Uri newURL, string newImageFile, string newDeviceGuid)
    {
        MACAddress = DeviceInfo.MACAddress;
        IPAddress = DeviceInfo.IPAddress;
        PortName = DeviceInfo.PortName;
        FriendlyName = newFriendlyName;
        URL = newURL;
        ImageFile = newImageFile;
        DeviceGuid = newDeviceGuid;
    }

#endregion

#region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

#endregion

#region Private Helpers

    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

#endregion

}


C#
public class DeviceViewModel
{
    private static ObservableCollection<Scanners> devices   = null;
    public static ObservableCollection<Scanners> Devices
    {
        get { return devices; }
        set { devices = value; }
    }

    public DeviceViewModel()
    {
        this.Initialize();
    }

    private void Initialize()
    {
        Reset();
    }

    public static void Reset()
    {
        devices = new ObservableCollection<Scanners>();
    }

    public static void Add(Scanners Scanner)
    {
        devices.Add(Scanner);
    }
}


The Path "ImageFile" in the XAML is a string which is the image's location. i.e. "Images\image1.bmp" The folder Images is located in the target folder containing bmp images. I can only display images in the cells if the images are added as resources in the project. I read a string from an INI class that describes the file name in the Images folder. There are other strings read from the INI file that appear in the other column. Only the images don't appear.

I don't what I am doing wrong, please help.
GeneralRe: Adding datagrid cell images at runtime doesn't appear in cell Pin
Christian Amado21-Jul-12 12:03
professionalChristian Amado21-Jul-12 12:03 
GeneralRe: Adding datagrid cell images at runtime doesn't appear in cell Pin
alleyes22-Jul-12 17:07
professionalalleyes22-Jul-12 17:07 
GeneralUnintended Save Issue WPF Pin
eddieangel20-Jul-12 7:20
eddieangel20-Jul-12 7:20 
GeneralRe: Unintended Save Issue WPF Pin
Ian Shlasko20-Jul-12 7:31
Ian Shlasko20-Jul-12 7:31 
GeneralRe: Unintended Save Issue WPF Pin
eddieangel20-Jul-12 7:37
eddieangel20-Jul-12 7:37 
GeneralRe: Unintended Save Issue WPF Pin
Ian Shlasko20-Jul-12 7:45
Ian Shlasko20-Jul-12 7:45 
GeneralRe: Unintended Save Issue WPF Pin
eddieangel20-Jul-12 7:49
eddieangel20-Jul-12 7:49 
GeneralRe: Unintended Save Issue WPF Pin
Ian Shlasko20-Jul-12 8:16
Ian Shlasko20-Jul-12 8:16 
QuestionButton Style Question Pin
Kevin Marois19-Jul-12 9:21
professionalKevin Marois19-Jul-12 9:21 
AnswerRe: Button Style Question Pin
Wayne Gaylard19-Jul-12 20:15
professionalWayne Gaylard19-Jul-12 20:15 
Questiontip for scrollviewer Pin
caradri18-Jul-12 23:10
caradri18-Jul-12 23:10 
GeneralRe: tip for scrollviewer Pin
Wayne Gaylard18-Jul-12 23:38
professionalWayne Gaylard18-Jul-12 23:38 
GeneralRe: tip for scrollviewer Pin
caradri19-Jul-12 1:16
caradri19-Jul-12 1:16 
GeneralRe: tip for scrollviewer Pin
Mycroft Holmes19-Jul-12 12:48
professionalMycroft Holmes19-Jul-12 12:48 
GeneralRe: tip for scrollviewer Pin
Christian Amado19-Jul-12 17:43
professionalChristian Amado19-Jul-12 17:43 
GeneralRe: tip for scrollviewer Pin
Pete O'Hanlon19-Jul-12 20:20
mvePete O'Hanlon19-Jul-12 20:20 
GeneralRe: tip for scrollviewer Pin
Mycroft Holmes19-Jul-12 23:19
professionalMycroft Holmes19-Jul-12 23:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.