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

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -