1

Hello i am new to wpf so i have one question

I want to allow user to upload new files in this one and then bind them to my pages suppose user wants to change the button ok then previous will be deleted and newer button will be appear i don't know how this gonna work

First i was thinking about relative path but that not gonna work for two pcs

i just want to make a user happen can change images of my application

so it will have a upload option and it will work for all pcs

Just code
  • 13,553
  • 10
  • 51
  • 93
  • it sounds like your asking if you can change the design of app dynamically? You'll need a plugin framework to do this (and its not simple by any means), try Prism, (http://compositewpf.codeplex.com/) – cjb110 Feb 20 '14 at 07:52
  • no @cjb110 i want to just change the button how can i handle this files the reason behind it is the clients requirements because client want to change the buttons onlny – Just code Feb 20 '14 at 08:10
  • @cjb110 Way to over engineer a simple problem. You on the Prism payroll? ;) You can "change an app dynamically" by swapping out view models, switching view states, starting animation storyboards, or using bindings with converters. But sod all the wpf features, lets download a dependency! – Gusdor Feb 20 '14 at 08:43
  • @Gusdor never used it:) just wasn't sure what the question was really after...and got it obviously wrong. – cjb110 Feb 21 '14 at 07:49
  • 1
    can you have a go at rewording your question? Its not clear what you would like to achieve? – cjb110 Feb 21 '14 at 07:50
  • What you don't understand in my question its just simple i want to just handle the files at runtime so if i have one exe user upload new files its should be handle globally not in a one pc on entire network @cjb110 – Just code Feb 21 '14 at 07:52
  • @downvoter pls add comment here – Just code Feb 21 '14 at 08:22
  • Do you mean a service that your wpf app can query to dynamically grab content? How about a common REST API that all apps can reach, and retrieve content dynamically? – Nicros Feb 24 '14 at 07:08
  • No @Nicros i don't have any idea about it can you give me some desc. or links would be preferrable – Just code Feb 24 '14 at 07:10
  • what have u tried so far???? – The Hungry Dictator Feb 24 '14 at 07:16
  • @KillerR what you want to see here – Just code Feb 24 '14 at 07:47

3 Answers3

2

As per your question, you mentioned upload an image. An upload is only possible when the image gets in a location which is accessible from any client machine.. like

  • a cloud database, where you can store the image as BLOB. or
  • a cloud storage where you can upload the images, and then retrieve from client machines.

EDIT:

Create a converter to convert the byte[] you fetched from DB. Import the resource to your wpf control and Bind the static resource to your image control.

class BinaryImageConverter : IValueConverter
{
    object IValueConverter.Convert( object value, 
        Type targetType, 
        object parameter, 
        System.Globalization.CultureInfo culture )
    {
        if(value != null && value is byte[])
        {
            byte[] bytes = value as byte[];

            MemoryStream stream = new MemoryStream( bytes );

            BitmapImage image = new BitmapImage();
            image.BeginInit();
            image.StreamSource = stream;
            image.EndInit();

            return image;
        }

        return null;
    }

    object IValueConverter.ConvertBack( object value, 
        Type targetType, 
        object parameter, 
        System.Globalization.CultureInfo culture )
    {
        throw new Exception( "The method or operation is not implemented." );
    }
}

<Image Source="{Binding Path=Image, Converter={StaticResource imgConverter}}" />

Please refer to this link for help in dynamic resources

Avishek
  • 1,896
  • 14
  • 33
  • Ya thanks i just want one example to change image resources i have used static resources if you can give me it would be great – Just code Feb 24 '14 at 07:22
  • do you want to save the image in a cloud storage? or cloud DB? – Avishek Feb 24 '14 at 07:24
  • i want to store it in a db and then retrieve from it but i have 10 pages and images should be fetched from one location – Just code Feb 24 '14 at 07:24
  • you can refer to this link http://codezone4.wordpress.com/2012/06/24/save-and-retrieve-images-in-wpf-from-database/ let me know if this doesn't work for you. – Avishek Feb 24 '14 at 07:27
  • Thanks how can i use this for static or dynamic resources? – Just code Feb 24 '14 at 07:29
  • Exact requirement what i need i already have implemented it i have saved image into database now i have image in a byte[] format i just want to change the image source in a `imgConverter` static resource which i have applied in all pages like this ``So i want to change image source of `RedOnOffButtonSmall` – Just code Feb 24 '14 at 07:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48231/discussion-between-avishek-and-dholakiyaankit) – Avishek Feb 24 '14 at 07:54
1

Well if all apps need to be updated with content (the image in the 'Ok' button for example) that someone updates, then all apps need to have access to a common location. It makes sense to make that location a website URL, where they can pull down content.

You could create a .NET WebAPI2 site that serves up that content. And each app is configured to check that site for new content on startup or something similar. For example, each app could startup and hit http://yourwebsite/buttons/okimage or something like that. It checks to see if the image is new and if so, downloads it relative to itself and uses that image.

But why? Why are you using WPF for this? Why not create a actual web application where the images are already common to all 'apps'? Seems like the wrong technology to me for this requirement...

But if you have to use WPF, okay. Maybe this link will help?

Community
  • 1
  • 1
Nicros
  • 5,031
  • 12
  • 57
  • 101
  • Thanks man no actually wpf is right i just want to give user to change the view of my application so he can change the images – Just code Feb 24 '14 at 07:24
  • Upload newer one it should be fetched from one location and then i can serve but my problem is i have static resource so i just want to check every time that image is new then serve new one to 13 pages like this..... – Just code Feb 24 '14 at 07:26
  • So the 'just check every time that image is new' part means looking to see what image you currently have loaded, and then comparing it against the served one. If you need the newer one, have the app download it and then set the image source in codebehind (for example). Updating answer with a link to another SO question that might help. – Nicros Feb 24 '14 at 07:31
0

I guess you really don't want a complete new button, but just a different image on the button. In that case just make a new property in your viewmodel for the path and bind the image source to the path.

<Image Source="{Binding ImagePath}" />
David
  • 853
  • 8
  • 24
  • yes david you are right but in your case how image path will be dynamic ? i don't have application i have exe only to install in clients computer – Just code Feb 20 '14 at 08:17
  • can't you make a setting in your application? If you only want to change things by swapping files, just use a relative path. – David Feb 20 '14 at 09:08
  • No i don't have any idea about it – Just code Feb 20 '14 at 09:10