Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting a WPF button to visible within an IConnectionPoint event handler
    primarykey
    data
    text
    <p>I'm fairly new to C# and WPF programing and right now this problem is giving me headaches.</p> <p><strong>What the program should do:</strong> The program displays a welcome screen with a text box, where a customer can enter his name. If the device comes near a Wireless Lan Access Points and connects successfully, a "Start" button on this main window should become visible.</p> <p><strong>What's not working:</strong> Setting the button visibility inside the event handler. The new style does not get applied. Furthermore, if I try to call any other code after setting the visibility attribute/property(?) it won't run (if I put a MessageBox.Show right before setting the visib. it will be shown, if I put it after setting the property, this code won't even be reached any more).</p> <p><strong>The code:</strong></p> <p>This is the button Element:</p> <pre><code>&lt;Button Height="72" HorizontalAlignment="Center" Margin="319,507,315,0" Name="buttonStart" VerticalAlignment="Top" Width="168" FontSize="32" Content="Los geht's" Click="buttonStart_Click" /&gt; </code></pre> <p>This is the event handler registration within the MainWindow.xaml.cs</p> <pre><code>public partial class MainWindow : Window, INetworkListManagerEvents { private INetworkListManager nlm_; private IConnectionPoint nlmICP_; private int nlmCookie_ = 0; private void InitNetManager() { nlm_ = new NetworkListManager(); IConnectionPointContainer icpc = (IConnectionPointContainer)nlm_; Guid tempGuide = typeof(INetworkListManagerEvents).GUID; icpc.FindConnectionPoint(ref tempGuide, out nlmICP_); nlmICP_.Advise(this, out nlmCookie_); } </code></pre> <p>And finally, the event handler:</p> <pre><code> public void ConnectivityChanged(NLM_CONNECTIVITY newConnectivity) { if (newConnectivity == NLM_CONNECTIVITY.NLM_CONNECTIVITY_DISCONNECTED || ((int)newConnectivity &amp; (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_NOTRAFFIC) != 0) { MessageBox.Show("Disconnected"); // this will code is reached buttonStart.Visibility = Visibility.Hidden; // this is not getting applied MessageBox.Show("Disconnected"); // this will code is not reached (stepped with debugger) } if ((((int)newConnectivity &amp; (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_LOCALNETWORK) != 0) || (((int)newConnectivity &amp; (int)NLM_CONNECTIVITY.NLM_CONNECTIVITY_IPV4_INTERNET) != 0)) { MessageBox.Show("Connected"); // see comments above buttonStart.Visibility = Visibility.Visible; } } </code></pre> <p>That's it - I hope you can help me.</p> <p>Thank you very much in advance for your efforts!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload