|
Hi,
When i say recursion, i mean that the flow of the algorithm will repeat it self depending the user input
|
|
|
|
|
We have many windows services on several servers.
How do you suggest to build a silverlight 4.0 application which monitors these services on servers?
I am thinking to have a functionality to check the status of each service on each server every so often i.e. every few seconds...
What are your thoughts please?
Thanks
|
|
|
|
|
You'd have to communicate with a backend web service, which polled these services to see if they were running or not. The Silverlight application would trigger the web service periodically (say every 10 seconds) and the results would be updated in a notifiable object.
|
|
|
|
|
Do you mean like having a timer inside a WCF to monitor changes every so often?
And then use the silverlight to check the WCF?
Please elaborate.
Thanks
|
|
|
|
|
I'd initiate this from the Silverlight side if I were you. Have Silverlight request the information from the service at timed intervals.
|
|
|
|
|
Do you mean to have the silverlight app to call the (WCF which checks all the windows services) ?
Thanks
|
|
|
|
|
|
|
You could also building an SL4 options with OOB option and COM support, but this could check windows services running on the client and not on the server.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Again on with my quest to learn WPF controls and improve our standard controls library to make it easier to use within a MVVM environment.
In this case I am looking for sggestions for how to best implemnt a standard button.
I would like to create a standard button which has an image and caption.
I understand that this is easily achieved using xaml, but ideally we would like a standard implementation so the button could be used in the following manor.
<CustomControls:StandardButton ButtinImage="Logout.jpg" ButtonCaption="Button Text"/>
How would you achieve this?
1. Inherit from the button class and add dependancy properties
2. Use Attached Properties and a style
3. Inherit fron UserControl using dependancy properties fro the image and caption
Thanks for your time
Just racking up the postings
|
|
|
|
|
I would, personally, go for 1 or 2.
2 is good if you are clear on how to create attached properties.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
If i go for one, I am assuming that I can do away for a controltemplate and just set the content to be an image object and a label programitcally based on the dependancy properties.
Does this sound right?
Just racking up the postings
|
|
|
|
|
If you want to have a bit of fun, you could always create a Blend Behavior which set the Content of the button.
|
|
|
|
|
Not sure that sounds like fun...
Just racking up the postings
|
|
|
|
|
It does to me (and it's very easy to do).
|
|
|
|
|
Afternoon Guys and Gals,
I am trying to learn how to implement Custom Controls in WPF for use in a reusable controls library because I am not happy with the current implementation as our current method does not play well with MVVM.
As an experiment I am trying to create a custom control that has two ListViews and two buttons, the idea being to allow a user to bind to SelectedItems and DeSelectItems properties in the view. These will populate the two list boxes from properties in a viewmodel. The buttons simply allowing the user to select an item and move it from one ListView to the other, ie selected / not selected.
The problem I have is that when I bind to the SelectedItems and DeSelectedItems in xaml, neither dependancy property in the custom control actually get populates, ie the lists stay empty.
I believe my mistake is related to Binding Source, something I do not understand so well
The Custom Control Source - (The Test application is implemented as MVVM)
namespace CustomControlLibrary
{
[TemplatePart(Name = DualListControl.ElementNotSelectedList, Type = typeof(ListView))]
[TemplatePart(Name = DualListControl.ElementSelectedList, Type = typeof(ListView))]
[TemplatePart(Name = DualListControl.ElementSelectButton, Type = typeof(Button))]
[TemplatePart(Name = DualListControl.ElementDeselectButton, Type = typeof(Button))]
public class DualListControl : Control
{
const string ElementNotSelectedList = "ElementNotSelectedList";
const string ElementSelectedList = "ElementSelectedList";
const string ElementSelectButton = "ElementSelectButton";
const string ElementDeselectButton = "ElementDeselectButton";
ListView _NotSelectedList, _SelectedList;
Button _SelectButton, _DeselectButton;
RelayCommand _SelectItemCommand, _DeSelectItemCommand;
static DualListControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DualListControl), new FrameworkPropertyMetadata(typeof(DualListControl)));
}
public DualListControl()
{
_SelectItemCommand = new RelayCommand(p => SelectItemCommandExecute(), p => SelectItemCommandCanExecute);
_DeSelectItemCommand = new RelayCommand(p => DeSelectItemCommandExecute(), p => DeSelectItemCommandCanExecute);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_NotSelectedList = GetTemplateChild(ElementNotSelectedList) as ListView;
_SelectedList = GetTemplateChild(ElementSelectedList) as ListView;
_SelectButton = GetTemplateChild(ElementSelectButton) as Button;
_SelectButton.Command = _SelectItemCommand as ICommand;
_DeselectButton = GetTemplateChild(ElementDeselectButton) as Button;
_DeselectButton.Command = _DeSelectItemCommand as ICommand;
}
bool SelectItemCommandCanExecute { get { return true; } }
bool DeSelectItemCommandCanExecute { get { return true; } }
void SelectItemCommandExecute()
{
if (!SelectItemCommandCanExecute)
return;
}
void DeSelectItemCommandExecute()
{
if (!DeSelectItemCommandCanExecute)
return;
SelectedItems.Add(_NotSelectedList.SelectedItem);
DeSelectedItems.Remove(_NotSelectedList.SelectedItem);
int i = 0;
}
public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(ObservableCollection<object>), typeof(DualListControl), new UIPropertyMetadata(new ObservableCollection<object>()));
public static readonly DependencyProperty DeSelectedItemsProperty =
DependencyProperty.Register("DeSelectedItems", typeof(ObservableCollection<object>), typeof(DualListControl), new UIPropertyMetadata(new ObservableCollection<object>()));
public ObservableCollection<object> SelectedItems
{
get { return (ObservableCollection<object>)GetValue(SelectedItemsProperty); }
set { SetValue(SelectedItemsProperty, value); }
}
public ObservableCollection<object> DeSelectedItems
{
get { return (ObservableCollection<object>)GetValue(DeSelectedItemsProperty); }
set { SetValue(DeSelectedItemsProperty, value); }
}
}
}
The Generic.xaml
<Style TargetType="{x:Type local:DualListControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:DualListControl}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListView Grid.Column="0" Name="ElementNotSelectedList" ItemsSource="{Binding Path=DeSelectedItems}"/>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button Grid.Row="1" Name="ElementSelectButton" Margin="5" Content="<"/>
<Button Grid.Row="2" Name="ElementDeselectButton" Margin="5" Content=">"/>
</Grid>
<ListView Grid.Column="2" Name="ElementSelectedList" ItemsSource="{Binding Path=SelectedItems}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The View
<UserControl x:Class="TestApplication.Views.MainAppView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:CustomControls="clr-namespace:CustomControlLibrary;assembly=CustomControlLibrary"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<CustomControls:DualListControl SelectedItems="{Binding SelectedItemsA}" DeSelectedItems="{Binding DeslectedItemsA}"/>
</Grid>
</UserControl>
The Modelview
namespace TestApplication.ViewModels
{
public class MainAppViewModel : BaseViewModel
{
ObservableCollection<object> _SelectedItems = new ObservableCollection<object>(),
_DeSelectedItems = new ObservableCollection<object>();
public ObservableCollection<object> SelectedItemsA
{
get { return _SelectedItems; }
}
public ObservableCollection<object> DeSelectedItemsA
{
get { return _DeSelectedItems; }
}
public MainAppViewModel()
{
_DeSelectedItems.Add("One");
_DeSelectedItems.Add("Two");
_DeSelectedItems.Add("Three");
_DeSelectedItems.Add("Four");
}
}
}
Appreciate anyone who can help to identify my mistake(s), 5's in the lounge as a possible bribe?
Just racking up the postings
|
|
|
|
|
I think I see your problem.
You guessed right... Your binding sources aren't set. By default, the binding source is the DataContext, and that's not what you want here. Since those bindings are inside the control template, you want to bind to the "TemplatedParent" (It's one of the options for RelativeSource).
ItemsSource="{Binding Path=SelectedItems,RelativeSource={RelativeSource TemplatedParent}}"
Even easier, though... There's a shortcut for that, which does exactly the same thing...
ItemsSource="{TemplateBinding SelectedItems}"
|
|
|
|
|
Ian,
Firstly, thanks for taking the time to look.
I have tried your suggestion and it has not yet resolved the problem, I do believe however that you have got me somewhat closer.
While trying this out, I notice that the actual dependancy properties SelectedItems and DeSelectedItems on the DualListControl class are not being set by the bindings, ie they are empty lists even though they shold (as far as I understand) be the same lists as thoose specified in the MainAppView.
With my test data, I am expecting the DualListControl.DeSelectedItems to contain the items "One", "Two", "Three", "Four" if you see what I mean.
Any ideas?
Paul
Just racking up the postings
|
|
|
|
|
Guess we only fixed half of the problem then... Now the template should be properly bound to the parent control, but are the parent control's properties actually binding to a MainAppViewModel?
Somewhere in your window code (Or wherever the MainAppView control is contained), you need to set the DataContext to a MainAppViewModel... Otherwise, the control has nothing to bind to.
|
|
|
|
|
Unfortunatly this is already done.
I have double checked and I can see while debugging that both the MainAppView and the DualListControl instance have the DataContext set to the same instance of the MainAppViewModel class.
The Content of the main window is set as follows
public MainWindow()
{
InitializeComponent();
Content = new MainAppViewModel();
}
And in the App.xaml i have a DataTemplate telling WPF how to render the object as follows
<Application x:Class="TestApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModels="clr-namespace:TestApplication.ViewModels"
xmlns:Views="clr-namespace:TestApplication.Views"
StartupUri="MainWindow.xaml">
<Application.Resources>
<DataTemplate DataType="{x:Type ViewModels:MainAppViewModel}">
<Views:MainAppView/>
</DataTemplate>
</Application.Resources>
</Application>
If you see what I mean
So the part that is missing is the actual binding of the DualListControls dependancy properties being bound to the MainAppViewModels SelectedListA and DeSelectedListA properties.
Any ideas as to what I have missed?
Just racking up the postings
|
|
|
|
|
Pardon the slow response... Busy busy... Anyway...
I'm running out of ideas here... Have you checked for any reported data binding errors? They don't pop up as exceptions, but if you bring up the Output window in your IDE, they should show up there.
|
|
|
|
|
You need to set the DataContext on your View to point to your model.
|
|
|
|
|
No, he has that part right, I believe... He's using a DataTemplate, so it goes like this:
1) MainWindow has its Content set to the model
2) Content is rendered using a DataTemplate which contains a MainAppView
(If this failed, he wouldn't see his control at all)
3) MainAppView, being inside a DataTemplate, uses that model as its DataContext
4) MainAppView contains a DualListControl, with its SelectedItems and DeselectedItems properties bound to that model
5) DualListControl is rendered using a DataTemplate, which contains two ListViews that are template-bound to those properties
It's a bit more indirect than I would have done, but it should work. #1 and #2 are solid... #3 is what you're talking about, but that should happen automatically. #5 is the TemplateBinding thing he already fixed... I think the broken link is in #4, just by process of elimination, but I don't see the actual problem.
|
|
|
|
|
Well, its a retarded way to do it and he should unretard it. Not make it more retarded . If he did it the correct way, he wouldn't be trouble shooting wacky issues. Oh wellz .
|
|
|
|
|
Concerning the Retaded way this is done, can you elaborate? I am not sure I understand what you think is wrong with my MVVM implementation.
I am not shooting or getting upset, please do not misread my comment in that way, I am only trying to learn.
All of the source code is available above. How would you achieve MVVM?
Just racking up the postings
|
|
|
|