|
Use DataGridTemplateColumn --> CellTemplate --> Image.
If no image is loaded and with no error then it must be a binding issue.
|
|
|
|
|
Hi,
I am new to silverlight. I have a web service method which returns a list. When i call it in the xaml page it is something like
webservice.myTestMethod() so where the return value goes. since we cannot assign the output directly to a variable how can we capture it
Thanks in advance
|
|
|
|
|
I assume this is a strongly typed list and you are trying to bind something from the xaml to it. If so, simply use an ObservableCollection to bind to, and fill it with the results of the web service call.
|
|
|
|
|
thanks for your reply can you pls explain with an eg. thanks
|
|
|
|
|
public ObservableCollection<MyClass> PropToBindTo { get; private set; }
private void FillData()
{
var data = new MyWebService().GetData();
foreach (var value in data)
PropToBindTo.Add(value);
} This is just an example, but if it isn't clear to you then you need to read up on the basics of Silvelight. I would suggest buying a decent book.
|
|
|
|
|
So playing with Silverlight 5 and I want to implement the doubleclick event on the datagrid, simple enough except the MouseLeftButtonDown does not fire.
If I use the MouseLeftButtonUp it fires but the e.ClickCount never seems to increment past the first click.
When testing against a TextBlock the event works perfectly - very irritating! Now I don't wish to template every cell in every DataGrid in the application so does anyone have any news on this issue.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Can someone please point me in the right direction? I'm already mostly bald, and I am pulling out what little hair that I have left!
Originally I had some XAML that looked something like this in my main window (I've left parts out for brevity):
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="TapeStream Management Console"
FontSize="20" TextAlignment="Center" VerticalAlignment="Center"/>
<TabControl Grid.Row="1">
<TabItem Header="Catalog">
<views:CatalogTab>
</TabItem>
<TabItem Header="Datasets">
... etc.
</TabItem>
... etc.
</Grid>
Under each tab item I had a UserControl that displayed the actual information. The DataContext for each UserControl was set in the code behind. Things rendered pretty much the way I expected. (Yeah, I know this UI is not going to win any awards, but it is a start.)
I had some issues with this implementation (trying to get a chance to prompt for the user to save changes when they switch to a different tab), and Collin Jasnoch[^] was kind enough to suggest an alternative approach. [^]
I got it to somewhat work after what he was telling me finally penetrated my thick skull (with a little extra pounding from Pete O'Hanlon[^]).
The problem that I have now is that it is rendering all screwy. The MainWindow XAML looks more like this now:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="TapeStream Management Console"
FontSize="20" TextAlignment="Center" VerticalAlignment="Center"/>
<TabControl Grid.Row="1" ItemsSource="{Binding ViewModels}" SelectedItem="{Binding SelectedItem}"/>
</Grid>
...
I now have a MainWindowViewModel class that is set as the DataContext for the MainWindow. It contains an ObservableCollection of my various ViewModels as per Collin's suggestion. I have a ResourceDictionary set up with the DataTemplates for my ViewModels / UserControls as suggested by Collin and Pete:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:TapeStreamManagementConsole.View"
xmlns:vms="clr-namespace:TapeStreamManagementConsole.ViewModel">
<DataTemplate DataType="{x:Type vms:CatalogViewModel}">
<views:CatalogTab />
</DataTemplate>
<DataTemplate DataType="{x:Type vms:DataSetsViewModel}">
<views:DataSetsView />
</DataTemplate>
<DataTemplate DataType="{x:Type vms:TapeImageFilesViewModel}">
<views:TapeImageFilesView />
</DataTemplate>
</ResourceDictionary>
1) I cannot figure out any way to get tab headers and make the TabControl look "normal".
2) My UserControls have a ListBox on the left-hand side that no longer has scroll bars.
I tried changing my DataTemplates to look like this:
<DataTemplate DataType="{x:Type vms:CatalogViewModel}">
<TabItem Header="Catalog" >
<views:CatalogTab />
</TabItem>
</DataTemplate>
When I do that, I end up with Tabs with headings, but no content! Help!
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
|
Hi,
using MVVM I'm looking for a general guideline that tells me what type I should use for properties in the viewmodel that are exposing lists.
I think, in general it is a good idea to keep the type as basic as possible (e.g. not ObjectSet<T> but IQueryable<T> or IEnumerable<T> ) in order to hide implementation from the interface. Thus, I started using IEnumerable<T> . Unfortunately it turned out, that the WPF designer (VS 2010) doesn't like this very much. The editor popup of the Properties view doesn't show me the members of my record type T . It seems that the designer needs at least IQueryable<T> , ICollection<T> or T[] .
Does anyone know a reason for this? I found no issues in using IEnumerable<T> at runtime, only at design time.
Thanks,
Harry
|
|
|
|
|
Unfortunately, the Cider designer isn't the greatest designer in the world. One thing though - if your types are going to need to update the UI based off changes, you must make sure that they implement INotifyCollectionChanged .
|
|
|
|
|
- Unfortunately, the Cider designer isn't the greatest designer in the world.
But should not VS be the greatest IDE and should not WPF be its greatest UI system?
- make sure that they implement INotifyCollectionChanged
That was the reason for me to put my records in a new container.
Thanks, Harry
|
|
|
|
|
I was aiming for something that didn't say "VS Cider sucks".
|
|
|
|
|
ObservableCollection is a minimal requirement for collection binding.
|
|
|
|
|
Well, it's not really. SL and WPF don't require it for update notification, rather they rely on the internal interfaces that ObservableCollection uses.
|
|
|
|
|
I did not mean he cannot use any other collection and ObservableCollection is the only collection that can be used.
My answer should have suggested that it could be prudent to use ObservableCollection as it already includes INotifyCollectionChanged implemented.
|
|
|
|
|
Coming back to my question, what do you think: Are there other drawbacks than bad designer support in using IEnumerable?
The background is the class AutoRefreshWrapper<T> in my article AutoRefresh Entity Framework Data Using SQL Server Service Broker[^]. Should I let it implement IQueryable or ICollection in order to make cider happy?
modified 12-Jan-12 13:00pm.
|
|
|
|
|
Thanks, Collin, for your comment
In addition, it seems that I've to implement IList too, in order to enable grid editing.
|
|
|
|
|
I agree totally and that is what I meant.
If you don't need notification support, any generic collection (IEnumerable or IList ) could suffice.
However, I wanted to suggest to the OP that if he needs binding update notification, then ObservableCollection should be an option to consider. Should have clearly mentioned that in my first answer.
|
|
|
|
|
Try to avoid other collections and stick with observableCollection or a derived implementation of that. As Ilist is far slower in binding than an ObservableCollection.
http://msdn.microsoft.com/en-us/library/bb613546.aspx[^]
Quote: Data binding the ItemsSource
Update time for 1 item (ms)
To a CLR List<t> object
1656ms
To an ObservableCollection<t>
20ms
|
|
|
|
|
I'm trying to display a tooltip on the column header of a DataGridTemplateColumn . The interwebs and StackOverflow's suggestions have been surprisingly unhelpful. A nudge in the right direction would be much appreciated. Basically what I want to do is replace this:
<data:DataGridTemplateColumn x:Key="EmployeeIdColumn"
Header="Employee ID"
Width="Auto" CanUserSort="True"
SortMemberPath="EmployeeId">
with this (obviously incorrect syntax, but hopefully the intent is clear):
<data:DataGridTemplateColumn x:Key="EmployeeIdColumn"
Header="Employee ID"
TooltipService.Tooltip="The employee's ID" <-- Tooltip
Width="Auto" CanUserSort="True"
SortMemberPath="EmployeeId">
Thanks,
/ravi
modified 11-Jan-12 12:11pm.
|
|
|
|
|
NM. The last answer on this[^] page works splendidly!
/ravi
|
|
|
|
|
Hi,
I have the following demo code:
[Serializable]
[DataContract(Name = "A", Namespace = "")]
[KnownType(typeof(B))]
public class A
{
public A()
{
Id = 0;
b = new B();
}
[Key]
[DataMember]
public int Id { get; set; }
[DataMember]
public B b { get; set; }
}
[Serializable]
[DataContract(Name = "B", Namespace = "")]
public partial class B : ComplexObject
{
public B()
{
Id = 0;
Description = string.Empty;
}
[Key]
[DataMember]
public int Id { get; set; }
[DataMember]
public string Description { get; set; }
}
The problem that I am having is that the RIA service is only generating the following object:
/// <summary>
/// The 'A' entity class.
/// </summary>
[DataContract(Namespace="", Name="A")]
public sealed partial class A : Entity
{
private int _id;
#region Extensibility Method Definition
#endregion
Can anyone please help me fix this problem, or explain why it does not generate the custom "B" Property?
Thanks
|
|
|
|
|
I've got a treeview containing hyperlinks. Their source is a NodeModel.
<HierarchicalDataTemplate DataType="{x:Type models:NodeModel}"
ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal"
Margin="2">
<TextBlock Margin="0,0,5,0">
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Command="{Binding Path=DataContext.SelectedLinkCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type views:ProjectListView}}}">
.
.
.
The hyperlink is bound to a command:
private ICommand _SelectedLinkCommand;
public ICommand SelectedLinkCommand
{
get
{
if (_SelectedLinkCommand == null)
_SelectedLinkCommand = new RelayCommand(SelectedLinkExecuted, SelectedLinkCanExecute);
return _SelectedLinkCommand;
}
}
and the command methods:
private bool SelectedLinkCanExecute()
{
return true;
}
private void SelectedLinkExecuted()
{
}
In the SelectedLinkExecuted method, how can I get a reference to the NodeModel?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Collin Jasnoch wrote:
The problem is getting the item. If you can find a way to get it you can pass it in using RelayComman<T>
There is no 'problem' involved in getting the item. You guys are half way to the 'correct' solution:
1) you are correct in that you have the VM expose a RelayCommand<T>. T in this case is going to be RoutedPropertyChangedEventArgs<object>.
2) the part of the puzzle that you guys are missing is an event to command mapper that is capable of forwarding the EventArgs as a command parameter.
#2 is absolutely necessary if you are writing a real MVVM app. How else are you going to forward control events to your VM?
The one I use in my MVVM framework is based off of MVVMLight's EventToCommand class. You simply create an interaction trigger for the event you are trapping and use the EventToCommand class to map it to the command and set the ForwardEventArgs=true. All via XAML.
|
|
|
|
|
Oh, my bad, I misread the OPs post. I originally read it as he was trying to click on the TreeViewItem node. He is not, so there is a much simpler way. My EventToCommand answer still stands as the "proper" way to forward control events to the VM, but that is not needed in this case.
For the sake of argument, here is how you would use the EventToCommand class:
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemKeyDown">
<wfx:EventToCommand Command="{Binding ElementName=stateCountyCtrl, Path=DataContext.KeyDownCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
You would put that in whatever object owned the event.
Then your RelayCommand<T> (the KeyDownCommand here) would take whatever EventArgs type the event is raising.
See my other response to the OP for the "correct" answer in this case.
|
|
|
|