c# - How do I handle blank strings and invalid Uri's in a text box bound to a uri property -
c# - How do I handle blank strings and invalid Uri's in a text box bound to a uri property -
in wpf application, have text box bound property uri.
<textbox grid.column="1" grid.row="10" margin="0,0,4,4" x:name="txtexporturl" text="{binding path=projectexporturl, mode=twoway}" visibility="{binding permissions.canexportjson, source={x:static services:applicationuserinfo.instance}, converter={staticresource booltovisibilityconverter}}"/>
i'm trying validation on string coming text box follows
private uri _projectexporturl; public uri projectexporturl { { homecoming _projectexporturl; } set { if(uri.trycreate(value, value.absoluteuri, out _projectexporturl)) _projectexporturl = value; else _projectexporturl = null; this.onpropertychanged("projectexporturl"); } }
the problem is, when string blank or invalid uri , trycreate
doesn't fail , go else statement. fails , nothing.
how can create sure blank strings , invalid uri's set null?
do mean that?
if(value == null || string.isnullorempty(value.tostring()) || !uri.trycreate(value, value.absoluteuri, out _projectexporturl)) _projectexporturl = null; onpropertychanged("projectexporturl");
not sure blank uri.
c# .net wpf uri
Comments
Post a Comment