M
M
Mikhail Usotsky2020-03-08 22:36:39
WPF
Mikhail Usotsky, 2020-03-08 22:36:39

How to get constants from another class for elements in DataTemplate?

Here is the DataTemplate code:

<DataTemplate DataType="{x:Type local:Interface}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="{x:Static cnst:Constants+Navigation+Width}"/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <ContentControl Grid.Column="0" Background="Red" Content="{Binding Spaces.Navigation}"/>
            
        </Grid>
    </DataTemplate>

And there is a class for it:
public class Constants
    {

        public class Navigation
        {
            public const int Width = 20;
        }

    }


Where local is the Interface class for MVVM. And cnst is a Constants class. I need some elements (as in this example) to take a common value from a set of constants to build a graphical interface. But something can't be obtained.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-03-09
@AquariusStar

As far as I remember, wpf does not know how to bind to fields, only to properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question