Click here to Skip to main content
15,498,622 members
Home / Discussions / WPF
   

WPF

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 4:09
cofounderChris Maunder16-Jul-09 4:09 
PinnedHow to get an answer to your question PinPopular
Chris Maunder16-Jul-09 4:05
cofounderChris Maunder16-Jul-09 4:05 
QuestionWhat's Wrong With This Style? Pin
Kevin Marois21-Nov-22 10:57
professionalKevin Marois21-Nov-22 10:57 
AnswerRe: What's Wrong With This Style? Pin
Gerry Schmitz21-Nov-22 11:17
mveGerry Schmitz21-Nov-22 11:17 
GeneralRe: What's Wrong With This Style? Pin
Kevin Marois21-Nov-22 12:44
professionalKevin Marois21-Nov-22 12:44 
QuestionStyle Question Pin
Kevin Marois20-Nov-22 11:30
professionalKevin Marois20-Nov-22 11:30 
AnswerRe: Style Question Pin
Richard Deeming20-Nov-22 23:37
mveRichard Deeming20-Nov-22 23:37 
GeneralRe: Style Question Pin
Kevin Marois21-Nov-22 9:05
professionalKevin Marois21-Nov-22 9:05 
Questionediting a WPF DataGrid Pin
pitwi13-Nov-22 10:08
Memberpitwi13-Nov-22 10:08 
AnswerRe: editing a WPF DataGrid Pin
Gerry Schmitz15-Nov-22 8:38
mveGerry Schmitz15-Nov-22 8:38 
QuestionCan I see the bounding box around WPF controls at runtime ? Pin
Maximilien27-Oct-22 4:16
MemberMaximilien27-Oct-22 4:16 
AnswerRe: Can I see the bounding box around WPF controls at runtime ? Pin
Richard Deeming27-Oct-22 5:05
mveRichard Deeming27-Oct-22 5:05 
QuestionCustom drawing ToggleButton when checked Pin
Maximilien17-Oct-22 10:12
MemberMaximilien17-Oct-22 10:12 
AnswerRe: Custom drawing ToggleButton when checked Pin
Gerry Schmitz17-Oct-22 11:11
mveGerry Schmitz17-Oct-22 11:11 
GeneralRe: Custom drawing ToggleButton when checked Pin
Maximilien24-Oct-22 3:48
MemberMaximilien24-Oct-22 3:48 
QuestionReferencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 3:24
MemberMaximilien5-Oct-22 3:24 
AnswerRe: Referencing DrawingImage in a binding. Pin
Richard Deeming5-Oct-22 6:29
mveRichard Deeming5-Oct-22 6:29 
The view-model shouldn't really know anything about your resources.

I'd suggest having an enum to represent the icon you want to display. Bind the source to that enum, and use a converter to convert the value to the relevant image.

Eg:
C#
public enum ChooseIcon
{
    Find,
    Search,
}

public class YourViewModel
{
    private ChooseIcon _chooseIcon;
    
    public ChooseIcon ChooseIcon
    {
        get { return _chooseIcon; }
        set { SetProperty(ref _chooseIcon, value); }
    }
}

public class ChooseIconConverter : IValueConverter
{
    public ImageSource FindIcon { get; set; }
    public ImageSource SearchIcon { get; set; }
    
    public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        switch ((ChooseIcon)value)
        {
            case ChooseIcon.Find: return FindIcon;
            case ChooseIcon.Search: return SearchIcon;
            default: return null;
        }
    }
    
    public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return Binding.DoNothing;
    }
}
XAML
<Window.Resources>
    <local:ChooseIconConverter
        x:Key="ChooseIconConverter"
        FindIcon="{StaticResource FindIcon}"
        SearchIcon="{StaticResource SearchIcon}"
    />
</Window.Resources>
...
<Image Source="{Binding ChooseIcon, Mode=OneWay, Converter={StaticResource ChooseIconConverter}}" />




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 8:14
MemberMaximilien5-Oct-22 8:14 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 8:55
MemberMaximilien5-Oct-22 8:55 
QuestionDesign Question Pin
Kevin Marois2-Oct-22 12:13
professionalKevin Marois2-Oct-22 12:13 
AnswerRe: Design Question Pin
Gerry Schmitz2-Oct-22 16:47
mveGerry Schmitz2-Oct-22 16:47 
QuestionLooking for a WPF control. Pin
Maximilien22-Sep-22 9:40
MemberMaximilien22-Sep-22 9:40 
AnswerRe: Looking for a WPF control. Pin
Richard Deeming22-Sep-22 22:39
mveRichard Deeming22-Sep-22 22:39 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 2:33
MemberMaximilien23-Sep-22 2:33 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 2:54
MemberMaximilien23-Sep-22 2:54 

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.