Click here to Skip to main content
15,882,278 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: editing a WPF DataGrid Pin
Gerry Schmitz15-Nov-22 7:38
mveGerry Schmitz15-Nov-22 7:38 
QuestionCan I see the bounding box around WPF controls at runtime ? Pin
Maximilien27-Oct-22 3:16
Maximilien27-Oct-22 3:16 
AnswerRe: Can I see the bounding box around WPF controls at runtime ? Pin
Richard Deeming27-Oct-22 4:05
mveRichard Deeming27-Oct-22 4:05 
QuestionCustom drawing ToggleButton when checked Pin
Maximilien17-Oct-22 9:12
Maximilien17-Oct-22 9:12 
AnswerRe: Custom drawing ToggleButton when checked Pin
Gerry Schmitz17-Oct-22 10:11
mveGerry Schmitz17-Oct-22 10:11 
GeneralRe: Custom drawing ToggleButton when checked Pin
Maximilien24-Oct-22 2:48
Maximilien24-Oct-22 2:48 
QuestionReferencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 2:24
Maximilien5-Oct-22 2:24 
AnswerRe: Referencing DrawingImage in a binding. Pin
Richard Deeming5-Oct-22 5:29
mveRichard Deeming5-Oct-22 5: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 7:14
Maximilien5-Oct-22 7:14 
GeneralRe: Referencing DrawingImage in a binding. Pin
Maximilien5-Oct-22 7:55
Maximilien5-Oct-22 7:55 
QuestionDesign Question Pin
Kevin Marois2-Oct-22 11:13
professionalKevin Marois2-Oct-22 11:13 
AnswerRe: Design Question Pin
Gerry Schmitz2-Oct-22 15:47
mveGerry Schmitz2-Oct-22 15:47 
QuestionLooking for a WPF control. Pin
Maximilien22-Sep-22 8:40
Maximilien22-Sep-22 8:40 
AnswerRe: Looking for a WPF control. Pin
Richard Deeming22-Sep-22 21:39
mveRichard Deeming22-Sep-22 21:39 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 1:33
Maximilien23-Sep-22 1:33 
GeneralRe: Looking for a WPF control. Pin
Maximilien23-Sep-22 1:54
Maximilien23-Sep-22 1:54 
QuestionWeird behavior with contextual menu not rendering properly. Pin
Maximilien21-Sep-22 7:00
Maximilien21-Sep-22 7:00 
AnswerRe: Weird behavior with contextual menu not rendering properly. Pin
Richard Deeming21-Sep-22 21:36
mveRichard Deeming21-Sep-22 21:36 
GeneralRe: Weird behavior with contextual menu not rendering properly. Pin
Maximilien22-Sep-22 8:22
Maximilien22-Sep-22 8:22 
QuestionConversion to .Net Core Issues Pin
Kevin Marois19-Sep-22 6:39
professionalKevin Marois19-Sep-22 6:39 
AnswerRe: Conversion to .Net Core Issues Pin
Richard Deeming19-Sep-22 21:20
mveRichard Deeming19-Sep-22 21:20 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois20-Sep-22 7:10
professionalKevin Marois20-Sep-22 7:10 
GeneralRe: Conversion to .Net Core Issues Pin
Kevin Marois22-Sep-22 5:57
professionalKevin Marois22-Sep-22 5:57 
GeneralRe: Conversion to .Net Core Issues Pin
Richard Deeming22-Sep-22 21:38
mveRichard Deeming22-Sep-22 21:38 
QuestionUsing Dependency Property's to Affect Non WPF Property's Pin
Marc Jeeves1-Sep-22 10:52
Marc Jeeves1-Sep-22 10:52 

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.