Posts

UWP/WinUI 2 - How to increase the maximum size of a Flyout

The Flyout is a useful class in UWP/WinUI 2 that allows you to display content in a popup. The Flyout class contains various useful built in behaviour such as showing and hiding animations and functionality to for dismissing the popup when it looses focus. One of the built in behaviours of the Flyout, is that it contains a ScrollViewer and a maximum size. This means that, if the content inside the Flyout becomes too large for the Flyout, the content will become scrollable. In some situations, this behaviour can be helpful, however, in other situations, you may want the flyout to simply size itself to fit its content rather than cutting content off and forcing the user to scroll to see the cut off content. Luckily, there's an easy way to do this by modifying a Flyout's FlyoutPresenterStyle. How to change the maximum size of a Flyout To change the maximum size of a Flyout, simply modify its FlyoutPresenterStyle like so (You can of course replace MaxHeight and/or MaxWidth with a d...

How to allow moving focus to and from the WPF WebView control using the Tab key in C# and VB

If you've ever used the WPF Microsoft Edge Legacy based WebView control (not to be confused with the Internet Explorer based WebBrowser control), you may have noticed that you can't use the Tab key to move focus to and from the said control and that only the mouse allows moving focus to and from it. You may also have noticed that using the WebView.Focus() method does not work. Luckily, the WebView contains both a function you can use to move focus to the WebView and an event which fires when the user attempts to move focus away from the WebView using the Tab key. How to move focus to the WebView using the Tab key We can moved focus to the WebView using the MoveFocus function of the WebView. In order to detect when the user attempts to focus the WebView, we can use a dummy button to detect the focus and then move it onto the WebView. XAML: < Button x : Name ="webViewFocusButton" Height ="0" Width ="0" Opacity ="0" GotFocus ="we...

How to specify referrer URI when navigating to a page in Storyboards WebView in Swift

 When navigating a Storyboards WebView to a new URI, you may want to specify a  referrer URI . When using the WebView, we can do this using the load function. To use this function, we need to create a URLRequest. From a URLRequest, we can add a value for referrer to the request, then pass it into the load function of the WebView like so. Swift: let myURL = URL(string "https://codingguides.quinnscomputing.com" ) var myRequest = URLRequest(url: myURL!) myRequest.addValue( "https://www.quinnscomputing.com" , forHTTPHeaderField: "Referer" ) self . WebViewMain .load(myRequest) This will navigate the WebView to the specified URI with the specified referrer URI. This snippet is available in Codly. Click the appropriate link below to download the snippet. If you don't have Codly, it is available here in the Microsoft Store . Download

How to specify referrer URI when navigating to a page in UWP WebView in C# and VB

When navigating a UWP WebView to a new URI, you may want to specify a referrer URI . When using the UWP WebView, we can do this using the NavigateWithHttpRequestMessage function. To use this function, we need to create a HttpRequestMessage. From an HttpRequestMessage, we can specify a URI to navigate to and referrer URI, amongst many things. C#: Windows.Web.Http.HttpRequestMessage Request = new Windows.Web.Http.HttpRequestMessage(); Request.Headers.Referer = new Uri( "https://www.quinnscomputing.com" ); Request.RequestUri = new Uri( "https://codingguides.quinnscomputing.com" ); webViewMain.NavigateWithHttpRequestMessage(Request); VB: Dim Request = New Windows.Web.Http.HttpRequestMessage() Request.Headers.Referer = New Uri( "https://www.quinnscomputing.com" ) Request.RequestUri = New Uri( "https://codingguides.quinnscomputing.com" ) webViewMain.NavigateWithHttpRequestMessage(Request) This will navigate the WebView to the specified URI with t...

How to show placeholder text in a WPF TextBox in C# and VB

Image
Sometimes, when you have a text box in a user interface, you may want to add placeholder text to that text box to give users a prompt as to what to enter into the text box. If you've ever used UWP or WinUI, you'll probably have noticed that the default text box elements provide a PlaceholderText property that provides this functionality. However, WPF and Windows Forms don't provide this functionality by default. Luckily, thanks to WPF's rendering capabilities, it is quite easy to set up placeholder text manually. If you're using Windows Forms, you can make use of the ElementHost to use a WPF TextBox. Typically, placeholder text is a slightly faded colour compared to user-entered text to help distinguish it and only shows when no text is entered into the text box. An example is below: How to show placeholder text in a WPF TextBox To show placeholder text in a WPF textbox, all we need to do is show a partially transparent, intangible Label above the TextBox like so (Y...