Autor Beitrag
csharpuser1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Do 08.12.16 11:36 
Hello,

I want to change the Visibility of a Label in a Tab according to a Value in another Tab.

I have two UserControls as my TabItem in my TabControl. Here some XAML.

ausblenden XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
        <TabControl x:Name="TabControl_1" SelectedIndex="0" TabStripPlacement="Left" HorizontalAlignment="Left" Height="700" Margin="10,10,0,0" VerticalAlignment="Top" Width="900" SelectionChanged="TabControl_SelectionChanged">
            <TabItem Header="ContainsValue" HorizontalAlignment="Right" Width="61">
                <tabdata:Value/>
            </TabItem>
            <TabItem Header="ChangesBinding">
                <Grid Background="#FFE5E5E5">
                    <tabdata:BindingClass/>
                </Grid>
        </TabControl>


So now, in my UserControl BindingClass, I have a Label.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
MyData myDataObject = new MyData();
        Binding visBinding = new Binding("_vis");
        
        public BindingClass()
        {
            InitializeComponent();
            visibilibtyBinding.Source = myDataObject;
            visibilibtyBinding.Converter = new System.Windows.Controls.BooleanToVisibilityConverter();
            Label1.SetBinding(Label.VisibilityProperty, visibilibtyBinding);

            int Value= ContainsValue.PinValues();

            if (Value> 143)
            {
                myDataObject._vis = true;

            }
            else myDataObject._vis = false;
        }


In MyData Class I have all the get set stuff. It works when i put in the constructor for example myDataObject._vis = true or false. But it never changes after first init. If I have the Value 150 first, it is visible after first init. But I cant change it after. The PinValues() function even returns the correct Value!



Sorry ich hab das grade erst gemerkt das ich hier im deutschen Forum bin.

EDIT: wenn ich einen Button auf in den UC BindingClass mache, kann ich die Value ändern in der ValueUC und bei ButtonKlick verschwindet oder erscheint das Label. Ich könnte einen Collapsed Button machen und einen Button klick simulieren..
csharpuser1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Do 08.12.16 12:29 
Alles was ich machen musste, war ein x:Name=".." in der zeile in der ich die tabdata dem Tabitem zugeorndet habe hinzuzufügen!