|
Where is the best place get get information on how to take a user control; like one downloaded from the Sliverlight Gallery, and add it to an exsisting project, or better yet create a completly new user control libabrary of all controls with a user control test suite project as part of the solution to bother verify the code works and the page load doens't hang, UI thread lock etc.
I recently downloaded the example code for the 'Binary Clock' on the Silver Light Gallery and modified teh animation so the dots changed colr based on the binary bit they were in. The control works just fin in blend 4 and runs smoothly, however when I load my page I get the blue sliverlight spinning gizmo and no page load.
So I attempted to just add the usercromtrol directly to the project instead of suing it as an asset from another project in the solution. no go!
Then I create a user control libabary, and got distracted, when I found MEF 2 Preview and patched it by lazy signing each class at build time, to demonstate in an article.
@ProtoBytes
|
|
|
|
|
Hi all,
I want to make a master detail screen. Get master and detail data from WCF service.
Dataform should get validation, error message etc.. from the class. but I can't get metadata from the WCF.
I try to Domain Service Class in WCF but I can't create context with Linq.
How can i use dataform with WCF. please help
S.A.A
|
|
|
|
|
|
Hello im new to Silverlight and i'm having a problem with consuming a WCF service. i have created a Currentname.cs that i use for databinding.
And news.cs where i store the data
The problem is when i call the service the it doesn't trigger the "event"
and populate the propery
Could anyone help?
<br />
<br />
private ObservableCollection<News> _PrivateNews;<br />
public ObservableCollection<News> _News <br />
{<br />
get<br />
{<br />
if (_PrivateNews.Count == 0)<br />
{<br />
getData();<br />
}<br />
return _PrivateNews;<br />
}<br />
set<br />
{<br />
_PrivateNews = value;<br />
if (PropertyChanged != null)<br />
PropertyChanged(this, new PropertyChangedEventArgs("News"));<br />
}<br />
}<br />
<br />
public void getData()<br />
{<br />
ServiceReference1.Service1Client newservice = new ServiceReference1.Service1Client();<br />
newservice.GetNewsCompleted += new EventHandler<ServiceReference1.GetNewsCompletedEventArgs>(newservice_GetNewsCompleted);<br />
newservice.GetNewsAsync();<br />
}<br />
<br />
void newservice_GetNewsCompleted(object sender, ServiceReference1.GetNewsCompletedEventArgs e)<br />
{<br />
<br />
ObservableCollection<News> myNews = new ObservableCollection<News>();<br />
foreach (ServiceReference1.P_GetSomeNewsResult x in e.Result)<br />
{<br />
News n = new News();<br />
n.Header = x.NewsHeader;<br />
n.Content = x.News;<br />
myNews.Add(n);<br />
}<br />
_News = myNews;<br />
}<br />
modified on Friday, October 22, 2010 8:56 AM
|
|
|
|
|
Looks like you are firing a property change for "News", but your property is called "_News".
|
|
|
|
|
Thanks, the binding works great now
|
|
|
|
|
I should source code for example to new project me it's about Assign Datagrid Value From Child Web Page To A Textbox In Parent Webform by silverlight. I don't know,How to write source code?..
|
|
|
|
|
I am having an issue with editing my data in a row details template. Has anyone experienced this issue? Here is some of the XAML:
<DataGrid
ItemsSource="{Binding AllInspections}"
AutoGenerateColumns="False"
Grid.Row="4"
Margin="5,0,0,0"
SelectedItem="{Binding SelectedInspection}">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBox
Text="{Binding Notes, Mode=TwoWay}" />
</DataTemplate>
</DataGrid.RowDetailsTemplate>
Save code is simple datacontext.SaveChanges()
The Binding Notes is displaying the information, but I can't get it to save and update. Nor anything I put into Row Details. When I include the field in the datagrid as a text box row it works fine. Thoughts?
P.S. After testing I see that the associated item (SelectedInspection) is not being updated nor is the observablecollection AllInspections. So putting the "Save" and datacontext updating aside, it looks like I cannot update the observablecollection from my rowdetails.
Cheers, --EA
P.P.S After messing around with this enough I ended up changing the binding of the textbox to:
Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}},Path=SelectedItem.Notes}" />
So I suspect the issue has something to do with the "SelectedItem" of the datagrid not being available to the RowDetailsTemplate. I am not sure why this would result in being able to display the data using {Binding Notes} and not edit it, but c'est la vie. If anyone has insight about this, I would appreciate it.
modified on Friday, October 22, 2010 5:06 PM
|
|
|
|
|
I am new to WPF, so bear with him.
I want to have a GridView with 2 columns, displaying custom controls, which has X amount of rows.
The data i am given is in a list format, which i then need to display as follows: i want to insert item 1 in column 1 and item 2 in column 2 for row 1. And then item 3 in column 1 and item 4 in column 2 for row 2, and so on - (Think of it a bit like a photo gallery)
The custom control will display the details for each item, which i have already created.
The problem i have is, how do i bind the data to the GridView.
My initial idea was to split the data into rows, i.e.: have several lists, that contain 2 items. This allows me to know that item 1 is for column 1 and item 2 is for column 2, i can then work my way through all the lists and end up with all the rows populated with the custom controls.
However, i cant work out how to programmtically add a new row, which should have a control in each column.
Am i going about it the right way? Or barking up the wrong tree...
Hopefully i've made sense.
Cheers.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I've changed my idea to have to have 2 stack panels, as this seems more fitting.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Solved.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I developed some userControl that contain some information check on the 'IsVisible' method ( override method ).
When i using this usercontrol on some window - i see some error because the 'IsVisible' method look for some variable that is set on run-time.
How can i check if I'm in design time and the system is not running ?
Thanks for the help.
|
|
|
|
|
|
hello,
I'm buzzy to create a custom listview witch has custom defined views based on the data it gets. I like
views with links such described in the example below and for example with a textbox and a textblock,
but it doesn't matter how it goes about it's idea.
I have a enum like this to know witch datatemplate must be used:
public enum tabType
{
tabbedTextBlock = 1,
tabbedLinkedBlock = 2
}
This class is a class to store data in
public class person
{
private string firstName;
private string lastName;
private int age;
private tabType type;
public person()
{
}
public person(string firstName, string lastName, int age, tabType type)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Age = age;
this.tabType = type;
}
public string FirstName
{
get;
set;
}
public string LastName
{
get;
set;
}
public int Age
{
get;
set;
}
public tabType tabType
{
get;
set;
}
a list of objects too be bind to the list
public class sampledata : ObservableCollection<person>
{
public sampledata() :base()
{
Add(new person("foo", "fofoo", 23, tabType.tabbedLinkedBlock));
Add(new person("apple", "fruit", 21, tabType.tabbedTextBlock));
Add(new person("pineapple", "fruit", 17, tabType.tabbedLinkedBlock));
Add(new person("banan", "fruit", 47, tabType.tabbedLinkedBlock));
Add(new person("kiwi", "fruit", 34, tabType.tabbedTextBlock));
}
}
the tabtype is used to let the custom listview class know witch type of datatemplate most be used.
I have searched for a view day's but couldn't found a nice working solution, only an idea but
it's written in VB.net with windows forms. It can be found here.
thx,
DJohn
|
|
|
|
|
I define some new button style.
The style default background is image X.bmp and when on 'mouseOver' is true the image is changing to Y.bmp
I have 10 buttons on the code that need to use this style - and each of the button need to show different image as default different image on 'mouseOver' event.
I can set the bitmap on each button on the button constructor - but i don't know how to set the image in this case on the style definition level.
Someone can help here ?
|
|
|
|
|
|
Hi,
I have a combo box and keyboard shortcut to it. When I use keyboard shortcut to access this combo box, focus is moving combo box but its items are not moving up/down with the help of arrow keys..
Following is my xaml..
<Label Content="Security _Level:" VerticalAlignment="Center" Target="{Binding ElementName=securityLevelCombo}" />
<ComboBox Grid.Column="1" x:Name="securityLevelCombo" Margin="8,0,0,0" IsReadOnly="True" VerticalAlignment="Center" SelectionChanged="securityLevelCombo_SelectionChanged"/>
Please help..
Thanks
|
|
|
|
|
Am I missing something here?
I wrote the usual "viewmodel locator":
public class ViewModelBase
{
public static readonly DependencyProperty ViewModelProperty = DependencyProperty.RegisterAttached("ViewModel",
typeof(System.Type), typeof(Window), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnViewModelChanged)));
public static void OnViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
d.SetValue(Window.DataContextProperty, Activator.CreateInstance((Type)e.NewValue));
}
public static void SetViewModel(DependencyObject d, Type value)
{
d.SetValue(ViewModelProperty, value);
}
public static Type GetViewModel(DependencyObject d)
{
return (Type)d.GetValue(ViewModelProperty);
}
}
Then I implemented a viewmodel like this:
public class Class1 : ViewModelBase
{
public String Test
{
get
{
System.Windows.MessageBox.Show("4");
return "Testing";
}
}
public List<String> Items
{
get
{
List<String> l = new List<String>();
l.Add("A");
l.Add("B");
return l;
}
}
}
then in my mainwindow.xaml, I just did:
local:ViewModelBase.ViewModel="{x:Type local:Class1}"
<TextBlock Background="Red" Text="{Binding Test}" Height="30" />
<ListBox Background="Green" ItemsSource="{Binding Items}" Height="100" />
works fine at runtime, but no data is shown at design time. I put a message box in OnViewModelChanged() and it does get called.
what do I need to do to see the bindings work at design time? I should point out I am using Visual Studio 2010.
|
|
|
|
|
Hmmm... I've found the whole d:DataContext="{d:DesignInstance Type=local:Class1}" thing... but it seems pretty flakey. If I paste it in, it might show the design time data once or twice, but when I rebuild, its gone again. Is there a way to set that automatically when I create the instance in OnViewModelChanged?
Not that it matters lol, since it doesn't work most of the time.
Any other ideas?
|
|
|
|
|
Say I have a dialog with a list box and 3 buttons: Add, Edit and Delete. The listbox displays a list of Widget objects.
I'm assuming the "proper MVVM way" is to do something like:
class ViewModel
{
public ObservableCollection<widget> Widgets { ... };
public Command AddCommand { ... };
public Command EditCommand { ... };
public Command DeleteCommand { ... };
}
Add then the ListBox.ItemsSource binds to Widgets, the Add button to AddCommand, Edit to EditCommand and so on...
Now is where I get confused on MVVM...
1) Typical Add button behavior is to auto select the new item. How would that happen? It was suggested to me that ViewModel expose a "CurrentItem" property for **2-way** data binding with the listbox. The AddCommand handler would update the CurrentItem after it creates it. Is this a good idea? To me, that seems hokey as it would force that behavior on everybody using the view model. Also, it would set that property in situations where it may not want to be set. Any ideas?
2) Obviously, Edit and Delete need to be disabled if no item is selected. I know how to do that the "non MVVM" way, but what is the MVVM way? I know the command has a CanExecute handler. Should all that logic happen in there? It would seem I would either need the list box or the selected item and the collection.
I guess I'm just trying to figure out where the line should be drawn at which code goes in the code behind and which goes in the view model.
I understand MVVM "purists" say ZERO code in the code behind, but it seems to me like you'll be creating a lot of properties, commands, etc and jumping through a lot of hoops to have all the bindable properties in the view model.
|
|
|
|
|
1) If there are certain situations you dont want the command to execute, the command should have a CanExecute property which can be set.
2) You achieve this through binding the enabled property of the command button to a property in your view model. This property should implement INotifyPropertyChanged . This property is then set to false triggering an INotify which will disable the button.
Hope this makes sesnse.
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.
modified on Monday, October 18, 2010 3:01 AM
|
|
|
|
|
We have implemented an observable list, a selected item and an editable item. The editable item is used as a throw away object to support the user cancelling an edit.
I also find I refresh a list from the database after a CRUD operation on one of the items. Getting all the related data for a complex item is a pita. Say if you add a chair and want the room, apartment, floor, building information on the chair object (as with a view) then getting all those items is tedious. Although I may be doing this quite wrong!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
SledgeHammer01 wrote: I understand MVVM "purists" say ZERO code in the code behind
Gah. That's just zealotry and stupidity rolled into one honking great pile of doggy poo. If the code doesn't touch on the model, there's no need to move it out of the view, e.g. you are updating a complex visual.
Typically, you'd have a SelectedItem in the VM and you'd simply have the CanExecute check to see if it's the default value or not.
SledgeHammer01 wrote: ypical Add button behavior is to auto select the new item. How would that happen? It was suggested to me that ViewModel expose a "CurrentItem" property for **2-way** data binding with the listbox. The AddCommand handler would update the CurrentItem after it creates it. Is this a good idea? To me, that seems hokey as it would force that behavior on everybody using the view model. Also, it would set that property in situations where it may not want to be set. Any ideas?
The VM should be there to support the view, so it exposes the behaviour that's appropriate for the view. I can't think of many instances where I've wanted to share one VM among different views so this may not be a real issue for you.
|
|
|
|
|
Hehe...
Ok, so if putting code in the code behind of a view is "allowed" in MVVM, what exactly is the point? I'll use my earlier example of a listbox and 3 buttons Add, Edit and Delete. Add is pretty much going to be a call to _model.Add(), delete is pretty much going to be a call to _model.Delete(), edit is pretty much going to be a call to _model.Update() or whatever. So, I would design my data access layer well and have add, edit and delete functionality THERE, not some chinsy view model. Now I don't mean put GUI stuff in the data access layer, but in my real world application, I have a data access layer that is something like:
public class Widget : INotifyPropertyChanged
{
}
public class Widgets :System.Collections.IEnumerable, INotifyCollectionChanged
{
}
So in this case, the view model would simply do something like:
public Widgets
{
get
{
return GetService<IDataStore>().Widgets;
}
}
that seems like adding a middle man class just for the hell of it doesn't it? I know I have seen some MVVM samples where the data access layer does NOT implement INotifyPropertyChanged and they do it in the VM... but to me that is hella retarded. I shouldn't need to re-implement INPC in every view model that consumes the data access layer objects.
So now the viewmodel seems to be a light weight redirection to the data store. Just to NOT have to put "listBox.ItemsSource = GetService<IDataStore>().Widgets;" in the code behind?
See, thats what I haven't wrapped my head around yet... trying to figure out what the hell the VM actually gives you in a real world application. I guess if you don't have a well designed data access layer it would make sense... but not having a well designed data access layer seems like a much bigger issue to me .
Thoughts? I'm seriously trying to figure this thing out.
|
|
|
|
|
Think about it from a slightly different perspective. Suppose that you have a page transition that doesn't have any reliance on a model, but is highly complex - where would you put the code for the trigger points in this? Would it make sense to put it in a ViewModel? Obviously not.
Now, suppose that your application has to interact with a model, this is where the VM comes into play. Stop thinking in terms of it being an unnecessary middleman - it's not, it's a vital layer in protecting and coordinating changes to your model. Most of the samples that you have seen tend to be fairly simplistic, with perhaps a single table being updated - this is not the way that it works in real life situations. Model interactions tend to be highly complex, with a single view potentially interacting with multiple model parts. The VM is vital for coordinating this. What people seem to get hung up on is that the VM simply seems to exist to provide details of INPC - this is not an accurate viewpoint (it's just that INPC plays an important part in updating the view). With a VM, you can isolate the logic of the view from the XAML that forms the view - which means that it becomes easier to test the application as you can test the VM without worrying about the view.
From a developers POV, the VM also allows you to decouple the design part of the application from the logic of the application, giving designers a chance to work with the code without having to have any knowledge about how to code themselves.
|
|
|
|
|