c# - How do I handle blank strings and invalid Uri's in a text box bound to a uri property -
In my WPF application, I have a text box that is a property that is a vertical one.
& lt; Text box grid Column = "1" grid. Line = "10" margin = "0,0,4,4" x: name = "txtExportURL" text = "{binding path = ProjectExportURL, Mode = TwoWay}" visibility = "{binding permissions.can export jason, source = { X: Static Services: ApplicationUserInfo.Instance}, converter = {Static Resource BulletWizibility Clip}} "/>
I am trying to verify on a string coming from the text box like
private Uri _projectExportURL; Public {Get Uri ProjectExportURL {Return} _projectExportURL; } Set {if (Uri.TryCreate (value, value.AbsoluteUri, out _projectExportURL)) _projectExportURL = value; Else _projectExportURL = Faucet; This.OnPropertyChanged ("ProjectExportURL"); }}
The problem is, when the string is empty or an invalid Yuri and it does TryCreate
, it does not fail and on the second statement It just fails and does nothing.
How can I make sure that the blank string and invalid URI are empty?
Do you mean it?
if (value == null) string.IsNullOrEmpty (value.ToString ()) ||! Uri.TryCreate (value, Value.AbsoluteUri, out_projectExportURL)) _projectExportURL = null; OnPropertyChanged ("ProjectExportURL");
Not sure that is empty Uri.
Comments
Post a Comment