Cannot Access Second Defined XAML Toolkit Expander on WinUI 3. #4740
-
Describe the bugHi,
I can access Expander x:Name="gitMetaExpander" from function directly. However I cannot access to Expander x:Name="chipsExpander" from function:
chipsExpander Definition:
Toolkit is defined also:
I saw.that, VS Designer cannot add "chipsExpander" to Mainpage.g.i.cs after build. It's as if single use is allowed with x:Name. Otherwise, I have Expanders without x:Name. This looks like an access issue. RegressionNo response Reproducible in sample app?
Steps to reproduce
Expected behaviorAll toolkit UI elements with x:Name must be accessible form code behind. ScreenshotsWindows Build Number
Other Windows Build numberNo response App minimum and target SDK version
Other SDK versionNo response Visual Studio Version2022 Visual Studio Build Number17.2.6 Device form factorDesktop Nuget packages
Additional contextNo response Help us help youYes, but only if others can assist. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 1 reply
-
Hello berkbb, thank you for opening an issue with us! I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌 |
Beta Was this translation helpful? Give feedback.
-
@berkbb I'm not sure if I follow your issue, there's a lot going on here. Can you provide a minimal set of information related to the issue you're seeing? If you're trying to access controls that are part of an item template, you can't do that with So, I don't think there's anything specific to Expander going on here, but it's a bit hard to follow your scenario and where the problem is with the code you provided. |
Beta Was this translation helpful? Give feedback.
-
Hi. I am out of city without any PC now. I cannot send ant sample but you can clone the sample from https://github.com/berkbb/tower_winui_case. Thanks @michael-hawker |
Beta Was this translation helpful? Give feedback.
-
I can access components from code behind via x:Name except one expander. It is a little bit strange 😏 I commented the issue on MainPage.xaml.cs. |
Beta Was this translation helpful? Give feedback.
-
@berkbb your Expander you call out is part of a DataTemplate here: You can't reference things in template in your code behind like that. You should be using data Binding on a property on the item the template represents to tackle handling the expanded state. In your case you're really using this for some function of the size of the window, in which case you should use an adaptive state trigger for a Visual State Manager to toggle the property. This isn't an issue with the Toolkit. |
Beta Was this translation helpful? Give feedback.
-
Hi @michael-hawker . I understand. But can you explain how can I use fist expander at code behind with x:Name ? The first expander is not in data template ? I'm using data bindings, I know that. Thanks. |
Beta Was this translation helpful? Give feedback.
@berkbb your Expander you call out is part of a DataTemplate here:
https://github.com/berkbb/tower_winui_case/blob/fbcbc31dbb701573f161d05c752e6d2f1cfca802/BBCase/Views/MainPage.xaml#L54-L55
You can't reference things in template in your code behind like that.
You should be using data Binding on a property on the item the template represents to tackle handling the expanded state. In your case you're really using this for some function of the size of the window, in which case you should use an adaptive state trigger for a Visual State Manager to toggle the property.
This isn't an issue with the Toolkit.