WinUI-Gallery
WinUI-Gallery copied to clipboard
ContentDialog - Value not in range
In WinUI desktop packaged is problem with showing ContentDialog. When I try show dialog, I get ArgumentException with message "Value does not fall within the expected range."
Code (I tried reproduce code from sample gallery, same result): private async void myButton_Click(object sender, RoutedEventArgs e) { var res = await (new ContentDialog()).ShowAsync(); myButton.Content = "Clicked"; }¨
Sample gallery version: 1.2.16.0
Windows 10 version: 20211 Settings of project
- Min. version: 17763
- Target version: 18362
@JanRajnoha - thanks for reporting this. Can you confirm if this the version of the Gallery from the master
branch or from one of the winui3
preview branches?
EDIT: reread, this is from the desktop packaged app.
CC: @mikehillberg @marb2000
WinUI 3 branch.
@Austin-Lamb I know that popups need to set the XamlRoot to work in desktop and xaml island scenarios and that when you don't you get an issue that looks a little like this. But looking at the code I think ContentDialog is setting the xaml root properly. Can you confirm?
@JanRajnoha and @stmoy if xaml controls gallery has a content dialog which is being created from code behind or in a resource dictionary (basically anywhere except in the visual tree) then you would need to set the XamlRoot property or get this exact error. From the code snippet it looks like this is what is happening, so I think this is infact an app issue.
Something like
var dialog = new ContentDialog();
dialog.XamlRoot = ThisPage.XamlRoot;
var res = await (dialog()).ShowAsync();
Ah, I see. I would have expected the winui3preview branch to have this fix since it's a known required dialog change.
CC: @MikeHillberg @marb2000
If the root control in your page is not 'sizable', the exception will be thrown. For example, you have a StackPanel in you page, and you must set the VerticalAlignment and HorizontalAlignment to "Stretch".
That's how I solve the problem......
如果你的页面里的根控件不是大小可变的(自动尺寸), 这个异常就会被跑出来. 举个栗子, 你的页面里面有个 StackPanel, 那么你必须设置 VerticalAlignment(垂直对齐) 和 HorizontalAlignment(水平对齐) 为 "Stretch(拉伸)".
这是我解决问题的方式...
If this is still an issue with the latest versions, please reactivate and give current repro steps and expected/actual results (or just create a new issue). Thanks!