Visifire/WPF databinding issues (Visifire v3.6.8) - wpf

I have a very basic databinding issue with the Visifire WPF charting tool in the last open-source version, v3.6.8, before it became commercial. I want to bind an ObservableCollection<> to the DataSource-Property of a DataSeries. It just doesn't work when I bind the property in XAML. When I bind the data in the code behind, it works fine.
I am using the collection for a DataGrid as well and there everything works fine.
The output log doesn't show any binding issues.
The get/set accessors of the DataSource property of the DataSeries object are never accessed when binding the property in XAML, I just don't get why. The dependency property is registered at creation of the DataSeries object.
Are there any known issues with this or am I missing something basic?
The XAML:
<DataGrid x:Name="grid" Grid.Column="0" ItemsSource="{Binding TransverseParallelShearLCS}"></DataGrid>
<Charts:Chart Grid.Column="1" x:Name="chart" ZoomingEnabled="True" AnimatedUpdate="True" ScrollingEnabled="False">
<Charts:Chart.Series>
<Charts:DataSeries RenderAs="Line" DataSource="{Binding TransverseParallelShearLCS}" AutoFitToPlotArea="True">
<Charts:DataSeries.DataMappings>
<Charts:DataMapping MemberName="XValue" Path="X"></Charts:DataMapping>
<Charts:DataMapping MemberName="YValue" Path="Y"></Charts:DataMapping>
</Charts:DataSeries.DataMappings>
</Charts:DataSeries>
</Charts:Chart.Series>
</Charts:Chart>

Please try the below sample example from Visifire Example Area and check.
http://visifire.com/silverlight_examples_details.php?id=10

Related

ComponentOne FlexGrid is empty

I just started using ComponentOne. Among other things, I need DataGrid with filtering capability for my WPF Caliburn.Micro application. So I tried to replace my common DataGrid with C1DataGrid, then C1FlexGrid, but in both cases the DataGrid was empty.
Here is my code:
<c1:C1FlexGrid x:Name="EnrollmentFiles" Grid.Row="1"
AutoGenerateColumns="False"
BaseControls:DataGridExtension.Columns="{Binding EnrollmentFileColumns}"
IsReadOnly="True"
SelectedItem="{Binding Path=SelectedEnrollmentFile, Mode=TwoWay}">
</c1:C1FlexGrid>
Could you please tell me what I am missing? Also, should I use C1DataGrid or FlexGrid?
Thanks
It's possible that by having SelectedItem bound the convention isn't working. If you're using the convention and want ItemsSource bound to EnrollmentFiles and you want to use SelectedItem, then create a property called SelectedEnrollmentFile and CM will do the SelectedItem binding too.

Get reference to Xaml object in view model

I have a an object created in Xaml:
<Grid>
<MyObject/>
</Grid>
I need someway to bind the object myObject back to a property in my view model. I dont know whether this is possible, everything ive seen so far binds properties together, but any help would be greatly appreciated.
I am assuming what you want is your ViewModel to hold the actual visual control MyObject in it and your Grid to display it via MVVM.
This is possible through ContentControl in WPF.
Assuming your ViewModel has a property MyObjectView which holds MyObject...
<Grid>
<ContentControl Content="{Binding MyObjectView}" />
</Grid>
Having said that you must take caution that same MyObjectView is not bound to any other content control as that will result in an error
"Specified element is already the logical child of another element.
Disconnect it first"
And if that requirement is possible then you must excercise ContentTemplate option.
Let me know if this helps.
It is possible. It kinda breaks mvvm though.
You can attach an InvokeCommandAction to this object, and bind the CommandParameter to it via ElementBinding. Then in the callback of the command which you defined in the viewmodel, you will have a reference to this object from the CommandParameter.

XAML DataContext and ViewModel Type

I use MVVM for my application, the DataContext of controls is assigned in my c# code (not in XAML).
Therefore the XAML controls have no idea to which instance type its DataContext is set to. The consequence is that there is no refactoring support and intellisense for the bound properties of my viewmodel in XAML.
Is there a way to tell a control in XAML to which type its DataContext is linked?
So when I modify a property name in my ViewModel or search for all references of that property, I want that this property in XAML bindings gets considered too.
There is no framework support, the best you can do is tell the VS designer the 'shape' of the DataContext so that it will give you hints for the properties. If you want to make your solution more refactor-proof, I would recommend Daniel's T4 metadata solution:
http://www.codeproject.com/KB/codegen/T4Metadata.aspx
This generatesmetadata for your view models which you can reference in the XAML:
<StackPanel DataContext="{Binding Source={StaticResource Person}}">
<TextBlock >Name:</TextBlock>
<TextBox Text="{Binding Path={x:Static Metadata:PersonMetadata.NamePath}}"/>
</StackPanel>
Colin E.
No, as the DataContext can change at runtime, it doesn't make sense to tie this to a particular type.

WPF binding to a boolean on a control

I'm wondering if someone has a simple succinct solution to binding to a dependency property that needs to be the converse of the property. Here's an example
I have a textbox that is disabled based on a property in the datacontext e.g.:
<TextBox IsEnabled={Binding CanEdit} Text={Binding MyText}/>
The requirement changes and I want to make it ReadOnly instead of disabled, so without changing my ViewModel I could do this:
In the UserControl resources:
<UserControl.Resources>
<m:NotConverter x:Key="NotConverter"/>
</UserControl.Resources>
And then change the TextBox to:
<TextBox IsReadOnly={Binding CanEdit,Converter={StaticResource NotConverter}} Text={Binding MyText}/>
Which I personally think is EXTREMELY verbose
I would love to be able to just do this(notice the !):
<TextBox IsReadOnly={Binding !CanEdit} Text={Binding MyText}/>
But alas, that is not an option that I know of.
I can think of two options.
Create an attached property IsNotReadOnly to FrameworkElement(?) and bind to that property
If I change my ViewModel then I could add a property CanEdit and another CannotEdit which I would be kind of embarrassed of because I believe it adds an irrelevant property to a class, which I don't think is a good practice.
The main reason for the question is that in my project the above isn't just for one control, so trying to keep my project as DRY as possible and readable I am throwing this out to anyone feeling my pain and has come up with a solution :)

How to set ItemsSource?

This dialog makes no sense to me
http://img576.imageshack.us/img576/4223/50709706.gif
And I'm having trouble finding good tutorials on it. Most of the examples aren't detailed enough, or do stuff via code, but I'd like to take advantage of the IDE as much as possible.
Whats the difference between ItemsSource and DataContext?
I'd like to bind it to just a List for starters. I don't need SQL or databases or anything fancy. Where would I declare my list? In MainWindow.xaml.cs? How do I get it to appear in that dialog?
Think of "DataContext" as the default value for "Source" in a binding.
When you create a binding, you can specify the path and source, like this (I'll use TextBox as an example):
<TextBox Text="{Binding Path=Foo,Source={StaticResource Bar}}" />
So my TextBox.Text property is bound to a Foo property on an object called Bar (a resource somewhere in the application).
However, if you have a whole bunch of things that you want to bind to properties on Bar, it's easier to set Bar as the DataContext of the parent container. A Binding without a Source will just use the DataContext by default, and DataContext flows through to child controls from the parent. So:
<StackPanel DataContext="{StaticResource Bar}">
<TextBox Text="{Binding Path=Foo}" />
<TextBox Text="{Binding Path=Fizz}" />
<TextBox Text="{Binding Path=Buzz}" />
</StackPanel>
All of the TextBoxes are still binding to properties on Bar, but they're doing it without setting it as a Source explicitly.
So let's have another look at the dialog you posted. It's giving you several options for the "source" of the ItemsSource binding. When you choose "DataContext", you're telling Visual Studio that the ItemsControl doesn't need to know the source - it'll pick it up from the DataContext of the parent container (maybe even the Window itself).
If you chose one of the other options (ElementName, RelativeSource or StaticResource) then you'd be setting the binding's source explicitly for that ItemsControl.
Once you've told it that it's binding to the DataContext, you'll need to drop into the "Path" section of the dialog and tell it which property to bind the items of the control to. In the end, the markup would look something like this (assuming it's a ListBox):
<ListBox ItemsSource="{Binding Path=Foos}" />
So the items in the ListBox are coming from a property called "Foos", and that property is on an object that's set in the DataContext somewhere higher in the logical tree (perhaps on the Window itself).
You rarely need to use the data context of a control outside of the control. The most common use case for setting DataContext(DataContext = this;) is within UserControl's code-behind to make all controls within the UserControl to bind to the control's properties.
When you use a ListBox, setting ItemsSource is sufficient, unless you are doing something funky.
This is a pretty good walkthrough: http://windowsclient.net/learn/video.aspx?v=315275
Specifically, you need to set the DataContext first to tell it where to look for the ItemsSource. The easiest way is to set this on the Window through the XAML:
<Window.DataContext>
<controllers:DownloadManager />
</Window.DataContext>

Resources