WinUI-Gallery icon indicating copy to clipboard operation
WinUI-Gallery copied to clipboard

ContentDialog - Value not in range

Open JanRajnoha opened this issue 4 years ago • 7 comments

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." image

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 avatar Nov 20 '20 21:11 JanRajnoha

@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

stmoy avatar Nov 20 '20 21:11 stmoy

WinUI 3 branch.

JanRajnoha avatar Nov 30 '20 23:11 JanRajnoha

@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?

StephenLPeters avatar Dec 01 '20 00:12 StephenLPeters

@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.

StephenLPeters avatar Dec 01 '20 01:12 StephenLPeters

Something like

var dialog = new ContentDialog();
dialog.XamlRoot = ThisPage.XamlRoot;
var res = await (dialog()).ShowAsync();

StephenLPeters avatar Dec 01 '20 01:12 StephenLPeters

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

stmoy avatar Dec 02 '20 00:12 stmoy

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(拉伸)".

这是我解决问题的方式...

SlimeNull avatar Mar 29 '22 14:03 SlimeNull

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!

bpulliam avatar Oct 17 '22 12:10 bpulliam