I'd like to bind to the element name of a node in my XmlDataProvider. I can't seem to get local-name() to work within my XPath expression. Does XAML support local-name()?
<TextBlock Text="{Binding XPath=local-name()}" />
I have been trying to do exactly the same thing and am pretty sure it is not supported in a single step.
The Binding.XPath help says
The XmlNode::SelectNodes method handles the XPath expressions from the XPath property. XPath functions are not supported.
However
You can work around it using a bit of a hack - you need a container around the element to provide a DataContext which is the result of your XPath and then you can query the LocalName property of that context object using Path, such as in my working example:
<StackPanel Grid.Row="20" Grid.Column="1"
DataContext="{Binding XPath=r:Result/r:LIC1}">
<TextBlock Text="{Binding Path=LocalName}" />
</StackPanel>
which I'd originally been trying to achieve with:
<TextBlock Grid.Row="20" Grid.Column="1"
Text="{Binding XPath=r:Result/r:LIC1/local-name\(\)}" />
Related
I am using an xceed DataGrid but I don't believe that matters here. What I need is how to get the databinding correct. I have a DataGrid column as follows:
<xcdg:Column FieldName="TestFieldValue"
Visible="False" Title="TestTitle"
GroupValueTemplate="{StaticResource TestFieldGroupTemplate}"/>
I am using a DataTemplate as follows:
<DataTemplate DataType="{x:Type testNamespace:TestFieldRecord}"
x:Key="TestFieldGroupTemplate">
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type xcdg:DataRow}},
Path=DataContext,
Converter={StaticResource TestFieldValueConverter}}" />
</DataTemplate>
First off, the value the property tied to this column field is just a long. The DataType here on the DataTemplate is actually the parent class of the column field property. An odd thing is if I just bind the text property in the data template like Text={Binding Converter={StaticResource TestFieldValueConverter}}, the converter still gets hit but with the long value from the column.
What I need here is to either bind to the DataRow's context, or to the the parent of the column TestFieldValue, which is the testNamespace:TestFieldRecord. Any find ancestor attempts have led me to no longer hitting my converter.
I think you need to use the Snoop tool to look at the tree and DataContext to see what's happening.
Going up a couple of levels in the tree, the DataContext will be a Xceed Group.
This group has a collection of items.
Your TestFieldGroupTemplate is applying to a Group.
So the main question is where is the group title coming from?
If you just want to change the group text, you can use a DataTemplate targeting Group.
(In the paid version TableflowView this will replace all their standard stuff).
Eg this passes the Group and DataGridControl to an IMultiValueConverter converter:
<DataTemplate DataType="{x:Type xcdg:Group}">
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource AnExampleConverter}">
<Binding Path="DataContext" RelativeSource="{RelativeSource TemplatedParent}"/>
<Binding RelativeSource="{RelativeSource AncestorType={x:Type xcdg:DataGridControl}}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
I have a pivot that I am trying to keep from gaining focus when the user hits the tab key. I immediately tried to set IsTabStop to false. However this wasn't keeping a user from tabbing into the pivot. So I tried testing IsTabStop on two buttons and the behavior was exactly what I expected from the pivot.
Here is my xaml:
<Pivot IsTabStop="False">
<PivotItem Header="Test">
<StackPanel Spacing="10">
<Button Content="Button 1" IsTabStop="True"/>
<Button Content="Button 2" IsTabStop="False"/>
</StackPanel>
</PivotItem>
</Pivot>
Am I missing something here or is there a way around this?
Setting tab index to -1 only makes it first, try something like 1001.. In here they explain the issue you may be having but for RichTextBlock, there are various attributes available for it to set.. https://learn.microsoft.com/en-us/windows/uwp/design/accessibility/keyboard-accessibility
So what i ended up doing is overriding the default style on the pivot. I changed the "HeaderClipper" in the style to have IsTabStop="False", this fixed my problem.
The documentation for the default pivot style can be found at https://msdn.microsoft.com/en-us/library/windows/apps/mt299144.aspx
I want to make a TextBlock visible only when a collection is empty. I have a ListView that is data-bound to the collection already and that's simple. I just want to display something else when the ListView is otherwise empty.
I wrote an IValueConverter that would take the collection, or count, or whatever I need, and return a Visibility appropriately. The XAML looks like this:
<TextBlock Visibility="{Binding Count, ElementName=ContactsList, Converter={StaticResource visibilityWhenEmpty}}"
Text="No contacts yet. Add one using the AppBar below." />
The trouble is that binding just the collection itself only calls my value converter once, when it's empty, and not again when the contents of the collection changes (kinda makes sense). And when, as shown above, I try binding against the collection's Count property, it doesn't call my value converter at all.
Any ideas?
I have faced the same issue. I applied a tricky solution. It might work for you as well. Taks a temporary combo box and bind the collection with that.
<ComboBox x:Name="TempComboBox"
ItemsSource="{Binding DataContext.ContactsList,
RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}" >
<ComboBox.Template>
<ControlTemplate>
<!--Add file button..-->
<TextBlock Content="Your text..."
>
<TextBlock.Visibility>
<Binding Path="Items.Count"
RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType=ComboBox}"
Converter="{StaticResource visibilityWhenEmpty}">
</Binding>
</TextBlock.Visibility>
</TextBlock>
</ControlTemplate>
</ComboBox.Template>
</ComboBox>
You could use notifyPropertyChanged for Count, or implement using BindableBase.
I am using the DataGrid of Silverlight toolkit. Now my requirement is to merge cell in some of the row in the datagrid.
Is there any way to do Cell merging in the Datagrid using silverlight.
If it's just displaying values from multiple columns in one column it is best to do this by using a DataGridTemplateColumn:
<sdk:DataGridTemplateColumn Header="Merged Cols">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Column1}" />
<TextBlock Text="{Binding Column2}" />
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
You could also do this through a converter if you want to use the DataGridTextColumn. As a Silverlight converter only supports one value you'd need to send the entire row.
The column definition of the DataGrid would contain
<sdk:DataGridTextColumn Binding={Binding Converter={StaticResource MergedCols}} />
You'd need to add the MergedCols converter to your solution and to your resource collection.
<UserControl.Resources>
<myConverters:MergedColsConverter x:Key="MergedCols" />
What is the syntax for using XPath with Binding in XAML? Are there any MSDN pages which describe where to put the braces?
Visual Studio doesn't like the following:
<TextBlock Text="{Binding XPath=/One/Two[#id='0']/Three/#Four}" />
I want the Text of the TextBlock to be set to the value of the Four attribute.
Looking at the documentation, you should set the binding using nested syntax as follows:
<TextBlock>
<TextBlock.Text>
<Binding XPath="/One/Two[#id='0']/Three/#Four" />
</TextBlock.Text>
</TextBlock>