① wpf 获取项目下文件夹路径
需求不太明确,开发期间与发布后的目录有可能是不一样的。
如图所示的解决方案,假如folderclass的路径可以用如下代码获取
stringdebug=System.AppDomain.CurrentDomain.BaseDirectory;
stringproj=System.IO.Path.Combine(debug,@"....");
foreach(stringfolderinSystem.IO.Directory.GetDirectories(proj))
MessageBox.Show(folder);//其中就可以遍历到你要的文件夹
如果你想绑定文件夹内的资源,其设置其属性为资源,并根据如下链接写xaml
http://msdn.microsoft.com/zh-cn/library/aa970069(v=vs.110).aspx
② 新手学习wpf的treeview!选择一个路径,如何获取该路径下所有特定类型的文件,并将他们绑定在treeview的中
前面:
<Grid>
<TreeViewName="tvDirectories"ItemsSource="{Binding}">
</TreeView>
<ButtonContent="Button"Height="23"HorizontalAlignment="Left"Margin="401,276,0,0"Name="button1"VerticalAlignment="Top"Width="75"Click="button1_Click"/>
</Grid>
后台:
privatevoidbutton1_Click(objectsender,RoutedEventArgse)
{
varlist=newList<string>();
stringpath=@"D:软件安装程序应用软件";//文件夹的路径
if(Directory.Exists(path))//判断要保存的目录文件是否存在。
{
vardirectory=newDirectoryInfo(path);
FileInfo[]collection=directory.GetFiles("*.exe");//指定类型
foreach(FileInfoitemincollection)
{
stringfullname=item.Name.ToString();
stringfilename=fullname.Substring(0,fullname.LastIndexOf("."));//去掉后缀名。
list.Add(filename);
}
tvDirectories.DataContext=list;
}
else
{
MessageBox.Show("文件夹不存在!");
}
}
③ wpf如何读取一个config配置文件格式的xml文件
<Title Row="0" Cloumn="2" ContentTitle="aaa" Assemblydll="aaa.dll" InterFace="aaaaaa" ImageUrl="pack://application:,,,/TyPlatform;component/Images/111.png" Width="180" Height="180" ></Title>
就像这样的一个XML,读成DataSet,然后这样取值
DataTable dt;
DataSet ds = new DataSet();
ds.ReadXml(Environment.CurrentDirectory + "/" + path);
dt = ds.Tables[0];
string Row = dt.Rows[index]["Row"].ToString();
string Cloumn = dt.Rows[index]["Cloumn"].ToString();
string Height = dt.Rows[index]["Height"].ToString();
string Width = dt.Rows[index]["Width"].ToString();
string ImageUrl = dt.Rows[index]["ImageUrl"].ToString();
④ c#- wpf架构读取xml配置文件到界面列表内,无思路求帮助
不用mvvm的话,so easy
新建 一个silverlight 4工程 在Window1.xaml加入一个comboBox1
后台中加个student 的类
public class Student
{
public string Name{get;set;}
public int Age{get;set;}
}
public Window1()
{
InitializeComponent();
List<Student> StudList =new List<Student>();
StudList.Add(new Student(){ Name="张飞",Age=21 });
StudList.Add(new Student(){ Name="曹操",Age=22 });
StudList.Add(new Student(){ Name="关公",Age=23 });
StudList.Add(new Student(){ Name="如花",Age=24 });
comboBox1.ItemsSource=StudList;
comboBox1.DisplayMemberPath="Name";
}
运行下看看
你List 想读配置喊顷文件的话Student 这个类唤渗袭就跟着变下,wpf基于属性绑定,不是事件驱动,想入门的话建议看下[深入浅出WPF完整版]刘铁猛出的,目前国人出的wpf就他的写的不错的书
还有你的配置文件应该是xml格式文件,要新建个MeterList的类 要用 System.Xml.XmlDocument这和兄个类来读配置文件,来填冲MeterList这个类
⑤ 关于wpf中获取路径问题
获取的没问题。因为调试状态下,目录就是..bin\debug\ 你可以把程序拷贝到别的盘运行起来测试就明白了。
⑥ WPF,资源文件是放在哪个文件夹的
1Addedfolders:Creategroups如果复资源文件是目录的话制,为资源文件创建组。当拖动一个包含资源文件的目录到项目中时,选择这个条目之后,在代码中引用资源文件就只需要直接写资源文件的路径,不用加上目录了。备注:在Xcode项目中,文件夹有两种颜色:黄色和蓝色。黄色代表的组,表明在项目文件中并没有实质性的文件夹,代码中可以直接通过文件名来获取资源。蓝色代表实体文件夹,表明在项目中存在着实质性的文件夹,代码中则需要通过深入目录来获取到资源文件。11Addedfolders:CreateFolderreference和上面的group选项相反,当拖动的是一个包含资源文件的目录时,会创建实质性的目录(显示为蓝色),代码中需要使用资源文件的时候路径必须带上目录。例子:如果项目文件中有个实体目录test/test1.h,在Xcode中test目录显示为蓝色,那么则需要#include“test/test1.h”;如果味黄色,之需要test1.h就可以了。
⑦ WPF 中.XAML文件如何读取资源文件
增加命名空间:
xmlns:resx="clr-namespace:你的Resources.Designer.cs打开以后的命名空间"
使用例子
Title="{x:Static resx:Resources.你资源名字}"
注意:回Resources.resx的访问修饰符必答须是public