User Profile & Activity

Chris Swain Member
Page
of 3
Posted: November 23, 2010 1:24 PM

Turning off the image loader did the trick!  Thanks!

I couldn't get the Content property to work, though. 

Posted: November 22, 2010 9:17 AM

I'm not talking about the UXStackItem, I'm talking about using the UXDesktopDockButton or just the UXDockButton.  They don't have a Header property. 

When using the UXStackItem, I can just specify an IconTemple instead of an Icon.  This is not possible in the UXDockButton. 

Posted: November 22, 2010 9:13 AM

Okay, here is what I've been trying to do and I think I may have uncovered a bug in the UXDesktopDockButton control:

I have a datasource with a propery of type UIElement that I'm trying to bind to the Icon property of the UXDesktopDockButton.  I created a converter that will convert the UIElement to a WriteableBitmap at the time of binding.  Now I can get the converter to work just fine on an Image control's Source property, but on the UXDesktopDockButton's Icon property I get a blank button.  See the sample code below or the attached project to recreate the issue:

Note: Ignore the bit about the DataTemplate in the converter, that code is not used yet. 

Coverter Code:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace SilverlightPlayground
{
    public class DependencyObjectToImageSourceConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int height = 16;
            int width = 16;

            if (parameter != null)
            {
                if (parameter is string)
                {
                    string rawParameter = parameter as string;
                    string[] paramArray = rawParameter.Split(',');
                    if (paramArray != null && paramArray.Length > 0)
                    {
                        int.TryParse(paramArray[0], out width);
                        int.TryParse(paramArray[1], out height);
                    }
                }
            }

            if (value is UIElement)
            {
                UIElement element = (UIElement)value;
                if (element is FrameworkElement)
                {
                    ((FrameworkElement)element).Width = width;
                    ((FrameworkElement)element).Height = height;
                }
                WriteableBitmap bitmap = new WriteableBitmap(width, height);
                bitmap.Render(element, null);
                bitmap.Invalidate();

                return bitmap;
            }
            else if (value is DataTemplate)
            {
                UIElement element = ((DataTemplate)value).LoadContent() as UIElement;
                if (element is FrameworkElement)
                {
                    ((FrameworkElement)element).Width = width;
                    ((FrameworkElement)element).Height = height;
                }
                StackPanel grid = new StackPanel();
                grid.Background = new SolidColorBrush(Colors.Green);
                grid.Width = grid.Height = 300;
                grid.Children.Add(element);
                ((Grid)((UserControl)Application.Current.RootVisual).Content).Children.Add(grid);
                grid.UpdateLayout();
                WriteableBitmap bitmap = new WriteableBitmap(width, height);
                bitmap.Render(grid, null);
                bitmap.Invalidate();
                //grid.Children.Remove(element);
                Image img = new Image();
                img.Source = bitmap;
                grid.Children.Add(img);
                grid.UpdateLayout();
                return bitmap;
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
MainPage.xaml:
<UserControl xmlns:Intersoft="http://intersoft.clientui.com/schemas"  x:Class="SilverlightPlayground.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:converters="clr-namespace:SilverlightPlayground"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <converters:DependencyObjectToImageSourceConverter x:Key="DependencyObjectToImageSourceConverter"/>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Image x:Name="BoundImage" Source="{Binding SomeUIElementProperty, Converter={StaticResource DependencyObjectToImageSourceConverter}, ConverterParameter='200,50'}"/>
        <Intersoft:UXDesktopDock>
            <Intersoft:UXDesktopDockButton Text="Test Button" Icon="{Binding SomeUIElementProperty, Converter={StaticResource DependencyObjectToImageSourceConverter}, ConverterParameter='50,50'}" />
        </Intersoft:UXDesktopDock>
    </Grid>
</UserControl>

 

MainPage.xaml.cs:

using System.Windows;
using System.Windows.Controls;

namespace SilverlightPlayground
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        public UIElement SomeUIElementProperty
        {
            get
            {
                Grid grid = new Grid();
                TextBlock text = new TextBlock();
                text.FontSize = 12;
                text.Text = "Hello World!";
                grid.Children.Add(text);
                return grid;
            }
        }
    }
}

Posted: November 20, 2010 8:09 PM

Still no takers on this problem?

Thanks Jimmy.  I am aware of the application framework, and it looks good.  If I didn't already have a lot of infrastructure built in order to use Prism, I would consider it.  But I don't want to go back and rewire my platform to take advantage of the framework. 

Given that, here is what I'm doing...

I'm using the UXDesktop in conjuction with the UXDesktopDock (a.k.a. Task Bar).  I will have a "Start Menu" UXDockButton that will serve as a Prism Region.  Prism will inject the apps that my platform will provide into the "Start Menu" region.  I plan to have a DesktopManager that will handle the "Start Menu" commands to launch apps.  When an app is launched, I want to add an "Instance Button" to the UXDesktopDock that will let the user know that app has at least one instance opened.  If an app is launched with more than one instance, then the DesktopManager will add that new instance to the "Instance Button" on the task bar.  The goal is to have the task bar work like the Windows 7 task bar.  I want the users to be able to "Pin" apps to it from the start menu by dragging a copy of the button down to the task bar.  And I want them to be able to see their app instances in the task bar grouped by app. 

Does this sound feasible?  Can you see any gotchas before I head down this road?

Posted: November 12, 2010 9:18 AM

Jimmy,

Thanks for the guidance.  Here is a little more info about what I need to do...

Background:  I'm developing a modular Silverlight platform that will accomodate 1-to-N applications.  I wanted to use the UXDock like a task bar or app bar of sorts.  The plan was to show the available apps in the bar, and use the UXStackItems to keep track of app instances. 

I suppose (based on your guidance) I could use it like my Windows 7 task bar and allow the users to add commonly used apps to it while by default providing a "Sart Menu" UXDockButton that would contain all of the apps.  Then, as users run apps, I could add them to the bar if they are not already "pinned". 

This approach will work to a point.  But as soon as a power user opens 50 different apps all at once, then the bar will need to scroll, or I'll need to calculate it's limit and begin grouping UXButtons as stack items in some sort of overflow UXButton.  If the overflow button is needed, would it be possible to show the overflow running apps as stack buttons and somehow still be able to show each apps' individual app instances?  For example, can a stack button contain another list of stack buttons?

All times are GMT -5. The time now is 3:33 AM.
Previous Next