我正在尝试查询web.Config
包含WCF条目的文件.
在<service>
节点中有一个name attribute
我想要匹配的节点.到目前为止,我的代码在进行匹配时已经起作用,但我的问题是它只返回1个<endpoint>
节点.
例如,我可以有这个xml片段:
<service name="a">
<endpoint>1</endpoint>
<endpoint>2</endpoint>
<endpoint>3</endpoint>
</service>
<service name="b">
<endpoint>1</endpoint>
<endpoint>2</endpoint>
</service>
Run Code Online (Sandbox Code Playgroud)
每当我得到一个匹配项时,我希望它显示<endpoint>
该匹配项的所有子节点.
这是我到目前为止的代码:
IEnumerable<XElement> xmlURL =
from el in xmlFile.Root.Descendants("service")
where (string)el.Attribute("name") == serviceString
select el.Element("endpoint");
Console.WriteLine("Start: " + serviceString);
foreach (XElement el in xmlURL)
{
Console.WriteLine(el);
}
Console.WriteLine("End: " + serviceString + "\n\n");
Run Code Online (Sandbox Code Playgroud)
目前,当匹配时,仅显示1个端点.
我正在尝试为Win8编写和读取本地存储.使用帮助器我能够成功写入我的机器,但读取.xml文件给我一个:mscorlib.dll错误中发生了System.UnauthorizedAccessException
我创建了一个codepaste,以便您可以看到我的代码.
代码在这里失败:
public async static Task<object> LoadData(string path, System.Type type)
{
var _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
try
{
var _File = await Folder.GetFileAsync(path);
using (IInputStream inStream = await _File.OpenSequentialReadAsync())
{
// Deserialize the Session State
XmlSerializer x = new XmlSerializer(type);
return x.Deserialize(inStream.AsStreamForRead());
}
}
catch (Exception ex)
{
MessageDialog dialog = new MessageDialog(ex.Message.ToString());
dialog.ShowAsync();
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
特别是在这一行:
using (IInputStream inStream = await _File.OpenSequentialReadAsync())
Run Code Online (Sandbox Code Playgroud)
如果你对我做错了什么有任何想法,它会帮助我很多.
我在Release Preview中这样做.如果我需要提供任何其他系统信息,请告诉我.
我在C#(4.0)中有一个常规的Queue对象,我正在使用访问此Queue的BackgroundWorkers.
我使用的代码如下:
do
{
while (dataQueue.Peek() == null // nothing waiting yet
&& isBeingLoaded == true // and worker 1 still actively adding stuff
)
System.Threading.Thread.Sleep(100);
// otherwise ready to do something:
if (dataQueue.Peek() != null) // because maybe the queue is complete and also empty
{
string companyId = dataQueue.Dequeue();
processLists(companyId);
// use up the stuff here //
} // otherwise nothing was there yet, it will resolve on the next loop.
} while (isBeingLoaded == true // still …
Run Code Online (Sandbox Code Playgroud) App.ViewModel.RefreshItems();
lbFruit.ItemsSource = App.ViewModel.ItemCollection;
Run Code Online (Sandbox Code Playgroud)
我在ItemsCollection中有重复项.在我的列表框中,我只想显示唯一值.我怎么才抓住那些展示?
我需要在这里表现出更多的数据做.
在我的集合中,我有一组数据可能包含集合中某些属性的重复项.
在我的视图模型中,我可以说我有水果和蔬菜作为属性.
我本可以有:
ItemCollection [0] .fruit ="Apple"ItemCollection [0] .vegetable ="Carrot"
ItemCollection [1] .fruit ="Pear"ItemColection [1] .vegetable ="Carrot"
ItemCollection [2] .fruit ="Apple"itemCollection [2] .vegetable ="Green Beans"
如果我只想在我的收藏中显示水果列表,我怎么能这样做而不重复?
例如,我的收藏中可以有多个水果和多个蔬菜.如果我只在我的列表中显示水果,我怎么才能显示:Apple,Pear,Orange
更多代码:
当我按照以下建议执行distinct时:lbFruit.ItemsSource = App.ViewModel.ItemCollection.Select(item => item.fruit).Distinct();
我得到2*(*是我列表的子弹,可以在DataTemplate的TextBlock中找到).
所以从技术上来说,Distinct正在运作,但是文本没有出现在*的旁边.如您所见,还有一个ProductNumber,我没有在原始示例中显示.但是,当我删除它时,我仍然得到相同的2*.
我是否需要在XAML方面做些什么才能做出独特的工作?此外,如果我想显示产品编号,我将如何将其添加到上面的选择(如果我们可以让它工作)?
<ListBox x:Name="lbFruit" ItemsSource="{Binding ItemCollection}" SelectionChanged="lbFruit_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
<TextBlock FontFamily="Segoe WP Semibold" FontWeight="Bold" FontSize="30" VerticalAlignment="Top" Margin="20,10">*</TextBlock>
<StackPanel>
<TextBlock x:Name="ItemText" Text="{Binding Fruit}" FontSize="{StaticResource PhoneFontSizeLarge}"/>
<TextBlock x:Name="ItemNumber" Text="{Binding ProductNumber}" FontSize="{StaticResource PhoneFontSizeNormal}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
希望这一切都有意义...感谢您的帮助!
我有一个ObservableCollection集合:historyItemCollection
当需要历史记录时,我会填充此集合.我遇到了一个错误,其中集合尚不存在(即没有历史记录).
当我尝试对此集合进行计数或以任何方式引用它时,我收到NULL引用错误....
检查此集合是否存在的最佳方法是什么?
我有几个不同的用户控件,它们动态构建并添加到最终位于VB6中的表单上的选项卡用户控件中.
我想要做的是,只要一个选项卡是活动选项卡,我想将标题文本更改为表单到选项卡的文本.
我在看SetWindowText
API,但我不知道该放在哪里.我把它放在表格上吗?我是否将它放在Tab用户控件或单个用户控件中.
如果还有其他SetWindowText
我应该使用的东西,请告诉我.
无论如何,当接到呼叫将数据添加到来电屏幕时?如果可能的话,我希望能够在该屏幕上添加文字.
更新:
如果目前无法在此屏幕上添加文字,是否有办法根据来电来触发代码?
我有一个相当简单的Windows 8 XAML/C#UserControl:
<UserControl
x:Class="periodicTable.cell"
x:Name="periodicTableCell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:periodicTable"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="100"
d:DesignWidth="65">
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="15"/>
<RowDefinition Height="20"/>
<RowDefinition Height="50"/>
<RowDefinition Height="15"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" x:Name="txtElementName"/>
<TextBlock Grid.Row="1" x:Name="txtAtomicNumber"/>
<TextBlock Grid.Row="2" x:Name="txtSymbol"/>
<TextBlock Grid.Row="3" x:Name="txtAtomicWeight"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我的代码背后是:
namespace periodicTable
{
public sealed partial class cell : UserControl
{
public string elementName { get; set; }
public string atomicNumber { get; set; }
public string symbol { get; set; }
public string atomicWeight { get; set; }
public …
Run Code Online (Sandbox Code Playgroud) 这适用于我的Windows 8应用:
在我的对象中,我有一个字符串属性,包含我想要使用的图像的路径.
public String ImagePath
Run Code Online (Sandbox Code Playgroud)
在我的XAML中,我设置了一个带有以下绑定的Image标签:
<Image Source="{Binding ImagePath}" Margin="50"/>
Run Code Online (Sandbox Code Playgroud)
当我引用我已包含在项目中的图像(在"资源"文件夹中)时,图像会正确显示.路径是:Assets/car2.png
但是,当我引用用户选择的图像时(使用FilePicker),我得到一个错误(没有图像).路径是:C:\Users\Jeff\Pictures\myImage.PNG
转换器无法将"Windows.Foundation.String"类型的值转换为"ImageSource"类型
只是添加更多信息.当我使用文件选择器时,我将文件位置转换为URI:
Uri uriAddress = new Uri(file.Path.ToString());
_VM.vehicleSingle.ImagePath = uriAddress.LocalPath;
Run Code Online (Sandbox Code Playgroud)
更新:
我也将此图像路径保存到隔离存储.我认为这就是问题所在.我能够保存所选文件的路径,但是当我在重新加载隔离存储时尝试绑定它时它不起作用.
因此,如果我不能在应用程序目录之外使用图像.有没有办法可以保存该图像并将其添加到目录中?
我尝试为我的模型创建一个BitmapImage属性,但现在我收到错误声明它无法序列化BitmapImage.
我有一个运行时间很长的脚本,我想包装其中可能包含多达100多个事务的事务。
我想实现一些错误处理和代码重用。我正在考虑使用标签和GOTO语句。
BEGIN TRY
BEGIN TRANSACTION abc
--DO SOMETHING
COMMIT TRANSACTION abc;
END TRY
BEGIN CATCH
GOTO ERROR_OUT
END CATCH
ERROR_OUT:
SELECT ERROR_MESSAGE() [ErrorMessage];
ROLLBACK;
Run Code Online (Sandbox Code Playgroud)
使用许多事务时是否应该这样做?
在我强制执行错误的简单测试中,我注意到ERROR_MESSGE()SELECT语句未返回结果。
有没有办法在使用标签时使select语句返回结果?
c# ×3
windows-8 ×3
xaml ×2
linq ×1
linq-to-xml ×1
queue ×1
silverlight ×1
sql ×1
sql-server ×1
vb6 ×1