Combobox binding in silverlight Ria Services - visual-studio-2010

I want to bind a combox with my entity model via domain services.
My entity model:
COUNTRIES (ID, NAME)
TABLE_TEST (PK_FIELD, FIELD2, COUNTRY_ID)
I created my entity model and the domain service.
My Xaml:
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:COUNTRIES, CreateList=true}" Height="0" Name="COUNTRIESDomainDataSource" QueryName="GetCOUNTRIESQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:DomainService1 />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:TABLE_TEST, CreateList=true}" Height="0" Name="TABLE_TESTDomainDataSource" QueryName="GetTABLE_TESTQuery" Width="0">
<riaControls:DomainDataSource.DomainContext>
<my:DomainService1 />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<ComboBox Name="COUNTRIESComboBox"
DataContext="{Binding ElementName=COUNTRIESDomainDataSource, Path=Data}" ItemsSource="{Binding}"
DisplayMemberPath="ID"
SelectedValuePath="NAME"
SelectedValue="{Binding ElementName=TABLE_TESTDomainDataSource, Path=COUNTRY_ID}">
</ComboBox>
The combobox is loaded with the correct values (all countries) but looks like it's not bounded with TABLE_TEST. When I change the register of TABLE_TEST, the value of the combo does not change.
What I am doing wrong? I looked many examples but no one is the same escenario, with domain data source and entity model.
I'm working with silverlight 5
Thanks

The DomainDataSource is an extremely bad fit as a datasource for Silverlight ComboBoxes. So far I've found Kyle McClennan's [MSFT] ComboBoxDataSource the most reliable in the use case you've described. In fact, he advised:
1) Do not use the DomainDataSource to populate ComboBoxes
You might
think this is drastic or an over reaction, but I stick by the
recommendation. Despite the simple samples you’ll see in other places,
I think you’re better off avoiding the DDS when working with
ComboBoxes. The DDS does not scale for more complex ComboBox
scenarios.
In particular, you need to mark your combobox as being Async in the final attribute.
<ComboBox Name="COUNTRIESComboBox"
DataContext="{Binding ElementName=COUNTRIESDomainDataSource, Path=Data}" ItemsSource="{Binding}"
DisplayMemberPath="ID"
SelectedValuePath="NAME"
SelectedValue="{Binding ElementName=TABLE_TESTDomainDataSource, Path=COUNTRY_ID}"
ex:ComboBox.Mode="Async">
</ComboBox>

Related

Is there a way to display a details view in .NET MAUI, like you do with the <details> tag in html?

Hello I am trying to display data on labels and I want to provide extra details about the data, when the user clicks on a button e.g. .
I know there is the tag in html, where you can define a summary and the details below.
Is there a way, or even better a ContentView, which can do that in .NET MAUI?
I've thought about adding a temporary label under the summary label, with the details, but that looks weird and is not intuitive.
If by details you mean a collapse / expander (which seem to be what details is in html) you can use the expander from the .net maui community toolkit :
<Expander>
<Expander.Header>
<Label Text="Baboon"
FontAttributes="Bold"
FontSize="Medium" />
</Expander.Header>
<HorizontalStackLayout Padding="10">
<Image Source="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
Aspect="AspectFill"
HeightRequest="120"
WidthRequest="120" />
<Label Text="Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae."
FontAttributes="Italic" />
</HorizontalStackLayout>
</Expander>
Otherwise if you just want to provide some additional texte about an element I would go with tooltips.
<Button Text="Save"
ToolTipProperties.Text="Click to Save your data" />

WP7: Listbox item template doesn't work when edited?

**UPDATED**
Just something quick, hope you guys can help me but i'm having this problem where I open up my wp7 project in blend and i edit the listbox item template and i finish it but. I save everything and go back to VS2010 for Windows phone and hit debug but i look at the phone and i have no items showing up at all. The listbox is just blank.
Code:
<ListBox toolkit:TiltEffect.IsTiltEnabled="True" x:Name="ListBox1" FontSize="42.667" FontFamily="Segoe WP SemiLight" IsSynchronizedWithCurrentItem="False" d:LayoutOverrides="VerticalAlignment">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="sp">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu IsZoomEnabled="False" >
<toolkit:MenuItem Header="Delete" Click="Delete_Click" Name="MenuItem1" />
<toolkit:MenuItem Header="Edit" Click="Edit_Click"/>
<toolkit:MenuItem Header="View" Click="View_Click"/>
<toolkit:MenuItem Header="Share.." Click="Share_Click"/>
</toolkit:ContextMenu>
Quick Brief
The app I'm making is a simple note app which saves notes in to a folder in the isolated storage. It successfully retrieves the items but i just want to make it so that it has the title and a brief description. This is all in one item. I've got to that point and the 2 textblocks have ="{Binding}" this basically just adds the title I'm assuming but i also added the ="{Binding}" to the second textblock so its basically showing the title for both of them. Is there a way to bind it to a specific item? like the second textblock, how can i bind that so that it shows 1st 12 characters inside a text file so basically it just shows the title and a brief description?
Maybe you have designtime-only data?
In case you're using Mvvm Light DataService approach, you define 2 DataServices: one for designtime and another for realtime.
Just random assuming. it would be nice to see some sample.
UPD: you posted wrong code, this one is about ContextMenu. I dont see binding there.
But again, generally talking, there shouldnt be any problems. You just deserialize data into model, say
public class Note
{
public string Name {get; set; }
public string Content; {get; set; }
}
And then you have List (or even ObservableCollection if you want realtime changes like renaming). And then you just bind
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Content}"/>
If you want to have a strict limit for Content/Description of 12 characters, you can add either Converter and take only 12 first characters, or introduce new property
class Note
{
***
public string Description { get { return Content.Substring(0, 12); } }
}
UPD2:
Ok, lets start from the very beginning. First, MVVM is recommended pattern for Wp7 applications. I believe, you can google info about it yourself, but here are the most important parts:
Model. Keeps your data (in your case, it is notes names and description).
ViewModel. This is abstract view. You have all logic here, you have all data prepared to be rendered here, but VM have no idea how to render data. In your case, a list of notes would be here.
View. Here is description of your ui. In your case, ListBox would be here.
So, first, make a new project, then use NuGet to install latest Mvvm Light (for example). After installing, you should see folders for viewmodels and models.
Create new class Note, like i described before. It would be your model.
Now, go to viewmodel. In a constructor, add a list of Notes there, call it ListOfNotes. Add manually several items to the list and initialize them (add some random values for Names and Contents fields).
Now, go to view. In the top of the file, there should be something like DataContext = "{Binding MainViewModel, Source={StaticResource ViewModelLocator}}". Inside of the view, add ListBox. It should be something like
<ListBox ItemsSource="{Binding ListOfNotes}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Content}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
So, what would happen now. When you would run your app, your view would be initialized. It would get MainViewModel (because is it set as DataContext, in step 4). In the constructor of MainViewModel, a ListOfNotes would be initialized (see step 3). Then, when page would load ListBox, it would try to find ListOfNotes inside of DataContext (MainViewModel in our case). It should find your list of Notes, and then, every element of the ListBox would be associated with every element of your ListOfNotes. As it is described in DataTemplate, it would try to get Note.Name and Note.Content.

Window Phone 7 and MVVM, Loaded event of a Page

Hi, I have a problem using the MVVM pattern after I instantiate my view model in this way:
<phone:PhoneApplicationPage.Resources>
<local:DetailVM x:Key="DetailVM"/>
</phone:PhoneApplicationPage.Resources>
How do I know when this Page is Loaded?
You can use the Blend SDK and add an event trigger that triggers a command in your viewmodel.
include
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
in your xmlns includes, and then add a trigger for the Loaded event.
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
The LoadCommand is simply a property that returns an ICommand. You should of course either set the DataContext of the page to your viewmodel, or set the source of the binding to the one in your resources.

Windows Phone 7 Databinding Outside Attributes (Nonstatic Hyperlink text)

I currently have a listBox in a WP7 application that uses databinding to populate it. The problem I'm having though is with this particular line:
<Hyperlink NavigateUri="{Binding LinkUrl}" TargetName="_blank">{Binding Name}</Hyperlink>
It seems that I can't bind things in this way (outside of an element's attributes). All this does is create a hyperlink with the literal text {Binding Name} linked to the url. Instead what I'm looking for is for it to use the actual Name variable in its place.
I've tried googling for an answer and looked into the Inlines attribute, but I keep coming up empty handed.
Any help would be appreciated
In WPF, the space between the tags is usually the 'content' (but not always) and bindable via the Content property. I'm unfamiliar with <Hyperlink> in Windows Phone, but a <HyperlinkButton> should work just as well.
<HyperlinkButton NavigateUri="{Binding LinkUrl}" TargetName="_blank" Content="{Binding Name}"/>
EDIT: For a <Hyperlink> in a <RichTextBox> try this:
<RichTextBox>
<Paragraph>
<Hyperlink>
<Hyperlink.Inlines>
<Run Text="{Binding Name}"/>
</Hyperlink.Inlines>
</Hyperlink>
</Paragraph>
</RichTextBox>

Bing map on WP7

How can i display a list of positions (from a xml document:using xml reading) in a Bing map with WP7? The idea is similar to Foursquare.
Microsoft wrote a good throughout tutorial on the subject, that also explains how to use databinding, so you can do proper code and view seperation.
It all relies on instances of Pushpin that are placed on a map layer. You can see a short working sample here.
The tutorial linked by Claus nicely points out how you can use Pushpins on a BingMapsControl. If you take out the essence of the tutorial this is the piece of code you want to use. All you need is a collection of items with at least a Location attribute. If you want your Pushpin to have a label you can also add a Name attribute.
You can databind the collection of items to your mapcontrol by adding this piece of code within your BingMapsControl.
<maps:MapItemsControl ItemsSource="{Binding Items}" >
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<maps:Pushpin Content="{Binding Name}" Location="{Binding Location}"/>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
If you need any more explanation please refer to the tutorial mentioned by Claus

Resources