Home > Net >  WPF use Uri read the file
WPF use Uri read the file

Time:09-17


Recently in learning WPF custom controls, want to be able to read a certain path under the XAML file ,

The Layout in the framework behind me will generate DLL files, Demo is my test program,
Demo of the bin file I'm going to store all kinds of resource file,

Now I want to use the Application. LoadComponent (uri) read the resource file,
Problem is the URI of the method is a relative path, I always can't find the path of the configuration of resource file,
Consult a great god!!!!!!

CodePudding user response:

System. The Environment. CurrentDirectory on your relative path

CodePudding user response:

refer to the second floor killed matt, bull response:
System. On the Environment. CurrentDirectory your relative path

Uri can only read the relative path, or you can't read

CodePudding user response:

Uri - pack://application:,,,,,,,,,,,,,,,,,

File
Drag the file into the project
App. The xaml








Or... Forget to baidu check read files, read the string
Public object XamlToObj (string xaml)
{
String strXaml=xaml;
StringReader strreader=new StringReader (strXaml);
XmlTextReader xmlreader=new XmlTextReader (strreader);
The object obj=XamlReader. Load (xmlreader);
Return obj.
}

CodePudding user response:

To answer the above, what path is not the problem, read the xaml, is a what thing, components or template or what style, change public object XamlToObj (string xaml) with this

CodePudding user response:

reference 5 floor desperaso reply:
above, what path is not a problem, read the xaml, is a what thing, components or template or what style, change public object XamlToObj (string xaml) use the


How to write a relative path is my core

CodePudding user response:

refer to 6th floor Dear200892 response:
my heart is how to write a relative path



Well, this
Var foo=new Uri (" pack://application:,,,/Style/ScrollViewer xaml ", UriKind. RelativeOrAbsolute);
Application, the Current Resources. MergedDictionaries. Add (new ResourceDictionary () {Source=foo});

CodePudding user response:

To answer the above, call
Style myStyle=(Style) enclosing FindResource (" for_scrollviewer ");//the key value inside the
Components. Style=myStyle;

CodePudding user response:

Relative paths do not need a component prefix, positioning directly to the include file folder, if the file has been generated and copied to the corresponding folder, the other is a file as a resource calls, resources in embedded into exe, can check it

CodePudding user response:

refer to the eighth floor desperaso response:
above, call
Style myStyle=(Style) enclosing FindResource (" for_scrollviewer ");//the key value inside the
Components. Style=myStyle;


Your this method can find the bin folder resource files?

CodePudding user response:

references to the tenth floor Dear200892 response:
you this method can find bin folder resource files?

Where not all the same, as long as drag scheme, pull the bin folder into the engineering plan,
Xaml is, if the external call, plain code file with the exe file to the user, just read the local, CSDN, on the search

CodePudding user response:

To answer the above, I am so make of https://blog.csdn.net/desperaso/article/details/105457489

CodePudding user response:

references 9 f exception92 response:
relative path does not need with component prefix, positioning directly to the include file folder, if the file has been generated and copied to the corresponding folder, the other is a file as a resource call, check the resources of embedded into exe, can distinguish

Under the bin file resource files can use the relative path?

CodePudding user response:

Probably thinking is not the same, the hope can help you,
A control that I finished write a cs file, such as
https://blog.csdn.net/desperaso/article/details/105340757
Component to add function has some functions, such as
Modify richtextbox https://blog.csdn.net/desperaso/article/details/105482979
Modify the textbox https://blog.csdn.net/desperaso/article/details/105364805
Style of what said above,
Reference, the hope can help

CodePudding user response:

On the 14th floor desperaso
reference response:
probably thinking is not the same, the hope can help you,
A control that I finished write a cs file, such as
https://blog.csdn.net/desperaso/article/details/105340757
Component to add function has some functions, such as
Modify richtextbox https://blog.csdn.net/desperaso/article/details/105482979
Modify the textbox https://blog.csdn.net/desperaso/article/details/105364805
Style of what said above,
Reference, the hope can help


Chat bubble before I download the software, I think the text frame should be able to wrap, the input expression, the cursor or behind the text

CodePudding user response:

reference 15 floor Dear200892 response:
chat bubble before I download the software, I think the text frame should be able to wrap, input expressions, or behind the text cursor

Line because the carriage return blocked, remove, shielding and paste, write off the cursor code, with/* */part, need to add

CodePudding user response:

Another, WeChat, etc, on the computer input box enter and other functionsnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related