What does Binding="{Binding (0)}" mean?
Asked Answered
Y

3

8

I found this:

<DataTrigger Value="True" Binding="{Binding (0)}">

triggers in RibbonMenuButton template. What does it mean? I've tried to google, but found nothing.

UPD more code:

<ControlTemplate x:Key="RibbonMenuButtonControlTemplate1" TargetType="{x:Type RibbonMenuButton}">
...
    <DataTrigger Binding="{Binding (0)}" Value="True">
        <Setter Property="TextElement.Foreground" TargetName="MainGrid" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
        <Setter Property="PathFill" TargetName="TwoLineText" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
        <Setter Property="CornerRadius" TargetName="OuterBorder" Value="0"/>
        <Setter Property="Background" TargetName="OuterBorder" Value="Transparent"/>
        <Setter Property="BorderBrush" TargetName="OuterBorder" Value="Transparent"/>
    </DataTrigger>
...

This code created in Blend after "edit template" button pressed on RibbonMenuButton control.

Yardman answered 19/2, 2014 at 11:30 Comment(4)
Are you sure there is no StingFormat with the binding? Can you post the reference?Halfhardy
Yes, I'm shure. This is full xaml.Yardman
Could you post more code or context please.Scevour
Added code to questionYardman
P
3

It looks like a bug. As far as I know, in WPF can not be Binding of this type. Below is a list of deficiencies, please pay attention to the first paragraph, quoted from connect.microsoft.com (archive):

I'm trying to style the ribbon control (System.Windows.Controls.Ribbon) and I keep running into problems.

  • If I use Blend or another tool to copy the default template of the Ribbon, the RibbonGroup, the RibbonTab, etc. these templates have errors. There are Bindings like {Binding (0)}.

  • I cannot change the height of the ribbon control.

  • It's not possible to change the template of the RibbonGroup, to change the appearance of the separator and to place the header in the top left corner of the group.

  • It's not possible to add a label to the ApplicationMenuButton. Furthermore this button has a fixed width.

  • I can't manage to remove the borders at the bottom of the ribbon control.

As I understand it, there is no hotfix.

Paperhanger answered 19/2, 2014 at 12:11 Comment(6)
Is this the code after calling XamlWriter.Save(controlName.Template, xmlWriter);???Scevour
@dev hedgehog: No, this is the source of ControlTemplate.Paperhanger
hehe, can you run XamlWriter.Save please if your VS can open the project.Scevour
@dev hedgehog: Unfortunately no, I have a studio version below and it will not open it.Paperhanger
The original MSFT link is dead so I added a link to an archived copyNeall
I reported this at developercommunity.visualstudio.com/content/problem/545784/…Neall
P
3

The only time this can appear is in the tokenized path format. See the code examples under "Indirect Targeting" in the Storyboards Overview. In XAML code, however, it's invalid. I imagine what happened was something like this:

// something goes wrong here, and GetProperties returns an empty array
var propertyChain = GetProperties();

var path = new PropertyPath("(0)", propertyChain);

trigger.Binding = new Binding { Path = path };

With an empty PathParameters, the XAML generator might then dump the raw tokenized path.

Precedential answered 19/2, 2014 at 13:52 Comment(0)
S
1

Sorry for placing this as answer but it doesnt fit in a comment.

Its still too less context you gave to us, however here is my guess.

Its a placeholder for something. Placeholders are rare in wpf world but usefull. That is all that I can think of right now with the information you gave to us. Its the only thing that makes sense to me.

I have seen few placeholders. Its a smart idea.

Usually if you have many different themes with different resource names you will end up creating such placeholders which will complete xaml file at pre or post build time.

Means you hit build action and after or before it compiles the xaml files will get combined and a tool provided by guys who wrote that ribbonbar will be executed to inject proper theme resource names instead of placeholders.

Anything could be placed instead of placeholders...

Where did you get that code from anyways? Can you use Snoop tool to see what is DataContext?

Provide us with more context please.

I would suggest you to dump the template in a file at runtime and then you will know what is going on.

Here is how:

var stringBuilder = new StringBuilder();
var xmlSettings = new XmlWriterSettings
{
  Indent = true
};

using (var xmlWriter = XmlWriter.Create(stringBuilder, xmlSettings))
{
  XamlWriter.Save(controlName.Template, xmlWriter);
}

If there is no (0) anymore in the template you dumped in a file at runtime then you will know its a f***ing placeholder. :) :) :)

Could you please test this out and let us know.

Scevour answered 19/2, 2014 at 12:16 Comment(2)
As I understand it, there is no DataContext. You can see the complete code by clicking on the link to connect.microsoft.com in my answer (RibbonTest2.zip in Attachments).Paperhanger
For some reason my VS crashes when I open that solution. Could you try save template at runtime with the code I posted? Let me know pls how it looks alike. It would be interesting to find out what Binding (0) is. To me it seems like a placeholder. Are there many Binding (0) in the ribbontest2 solution?Scevour

© 2022 - 2024 — McMap. All rights reserved.