Reputation: 128
I noticed a bit of a weird behaviour if i use a binding like
Text="{Binding ., Converter={StaticResource NavItemToCaptionConverter}}"
My Listview (Full List code below) doesnt show any text for this textblock. If i remove the "dot" at runtime the view updates and shows all items correct. but then i get a "Unexpected token 'Comma' on compile time.
The collection i am binding onto is a Observable collection filled with a few Enum items.
I Cant find where i made my mistake. Does anyone have an idea?
Here the full code for the ListView:
<ListView
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Center"
ItemClick="OnNavigationBarItemClicked"
ItemsSource="{Binding NavigationBarItems}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="10,15">
<Rectangle
Fill="DarkGray"
RadiusX="10"
RadiusY="10" />
<TextBlock
Margin="20,5"
FontSize="20"
Foreground="Black"
Text="{Binding ., Converter={StaticResource NavItemToCaptionConverter}}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Upvotes: 0
Views: 150
Reputation: 5868
The Binding Path=.
is available for WPF. In general, we use Binding plus a space to bind the current context.
<TextBlock Margin="20,5"
FontSize="20"
Foreground="Black"
Text="{Binding Converter={StaticResource NavItemToCaptionConverter}}" />
If i remove the "dot" at runtime the view updates and shows all items correct. But then i get a "Unexpected token 'Comma' on compile time.
When you remove the "dot" at runtime, it will just refresh by the content of Binding. But in compile time, it will check the complete xaml code and see if there are any syntax errors. So the 'comma' will give an error.
Upvotes: 2