Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I access a TabControl from within a class?
    primarykey
    data
    text
    <p>I'm a week into learning visual basic and I'm completely stuck.</p> <p>I have a TabControl with 2 TabItems in the XAML of a WPF:</p> <pre><code>&lt;TabControl Name="browser_tabs" Width="Auto" Height="Auto" BorderThickness="0"&gt; &lt;TabItem Header="My Page"&gt; &lt;DockPanel Name="tab1" Width="Auto" Height="Auto" Background="#fefefe" /&gt; &lt;/TabItem&gt; &lt;TabItem Header="Browser" Name="browserTab"&gt; &lt;DockPanel Name="tab2" Width="Auto" Height="Auto" Background="#fefefe" /&gt; &lt;/TabItem&gt; &lt;/TabControl&gt; </code></pre> <p>and I am trying to change the tab (programmatically / problematically) from a class, bookmarkControlsObj, within the MainWindow class:</p> <pre><code>Class MainWindow ... Public Class bookmarkControlsObj Public Sub follow(ByVal url As String) browser_tabs.selectedIndex = 1 '&lt;--- ahhhhhhhhhhhhhhhhhhh!' web_view2.Load(url) End Sub End Class End Class </code></pre> <p>But I keep getting "<code>Reference to a non-shared member requires an object reference.</code>" -- I have no idea how to share the XAML TabControl within the bookmarkControlsObj class.. and it's driving me crazy. Please help.</p> <p>EDIT:</p> <p>The reason I have a nested class is because I'm calling the "follow" Sub within the class from a cefsharp (chrome embedded) WebView housing a page with a Javascript function -- using the <code>RegisterJsObject</code> I'm able to call a vb.net method via Javascript. In this case I'm sending a url to the "follow" Sub which loads it in a browser contained in the second TabItem, but I want it to automatically switch to that tab before it loads -- Long story short, <code>RegisterJsObject</code> seems to only work if it is contained within a class.. though it's only nested because that's where it ended up.</p> <p>I'm able to access the browser in the second tab from the class because I declared it "shared" and added it to the TabItem -- but I'm not sure how to declare the TabControl (set visually) as Shared</p> <p>Here is a link to the RegisterJSObject if it helps any: <a href="https://github.com/ataranto/CefSharp/blob/master/CefSharp/CefSharp.h#L116" rel="nofollow">https://github.com/ataranto/CefSharp/blob/master/CefSharp/CefSharp.h#L116</a></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.
 

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