-3

I have this button from Main window.xaml need to call it from another class i made it just like first answer How to make a control in XAML public in order to be seen in other classes

 <Window x:Class="USD.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="450" Width="525"> 

<Button  ToolTip="Answer Call" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="107,82,0,0"  x:Name="answerCall"  Click="answerCall_Click"  Visibility="Hidden" x:FieldModifier="public">
        <StackPanel Orientation="Horizontal" >
            <Image  Width="35" Height="35" Source="Images/unnamed.png" RenderTransformOrigin="4.075,0.607">
            </Image>
        </StackPanel>
        <Button.Template>
            <ControlTemplate TargetType="Button">
                <Grid>
                    <ContentPresenter HorizontalAlignment="Center"
                              VerticalAlignment="Center"/>
                </Grid>
            </ControlTemplate>
        </Button.Template>
    </Button>

but when i checked it from any .cs class just like that

MainWindow.answerCall.Visibility.Visible;

give errors

bavs
  • 25
  • 7

2 Answers2

0

i fixed it by this in C# code

 DispatcherPriority.Background,
                    new Action(() => ((MainWindow)System.Windows.Application.Current.MainWindow).answerCall.Visibility = Visibility.Visible));
bavs
  • 25
  • 7
-1

If you use a controller/viewmodel, you shouldn't have any code behind, instead of that, you should work with bindable properties and commands, implementing INotifyPropertyChanged interface, in some base class if you want.

Sebastian Ferrari
  • 829
  • 1
  • 13
  • 20