我web-api返回一个用户对象.在那个对象中有一个DateTime属性.当我在我的应用程序中读取它时,我得到一个错误,因为代表DateTime的字符串无效,它丢失了\Date ...
{System.Runtime.Serialization.SerializationException:反序列化User类型的对象时出错.DateTime内容'1984-10-02T01:00:00'不以'/ Date('和'以'结尾'开头,如JSON所要求的那样.--->
public static async Task<User> GetUser(string email)
{
try
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url + "?email="+email);
if (response.IsSuccessStatusCode)
{
string content = await response.Content.ReadAsStringAsync();
User user = DataService.Deserialize<User>(content);
return user;
}
return null;
}
}
catch (Exception ex)
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我用来反序列化的方法.
public static T Deserialize<T>(string json) {
try
{
var _Bytes = Encoding.Unicode.GetBytes(json);
using (MemoryStream _Stream = new MemoryStream(_Bytes))
{
var …Run Code Online (Sandbox Code Playgroud) 我有多个Listviews,每个Listviews都绑定了自己的itemsource.但我只有1个选定项目.
所以例如我有5个列表框,(Monday, Tuesday, ...)每个列表框都有自己的itemssource (MondayList, TuesdayList, ...).这些Listviews SelectedItem属性中的每一个都绑定到属性'CurrentToDo'.
问题是,如果我在星期一选择一个,然后在星期二选择一个,他们都被选中.
因此,在所有列表视图中只能选择一个项目,请帮忙.
<UserControl.Resources>
<Style x:Key="ListViewItemStyleToDo" TargetType="{x:Type ListViewItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
</Style>
<GridView x:Key="ViewBase1" x:Shared="False" >
<GridViewColumn Header="" Width="30">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Subject" Width="auto" DisplayMemberBinding="{Binding Subject}" />
</GridView>
</UserControl.Resources>
<ListView Grid.Row="1" ItemsSource="{Binding MondayList}" SelectedItem="{Binding CurrentToDo, Mode=TwoWay}" SelectionMode="Single" ItemContainerStyle="{DynamicResource ListViewItemStyleToDo}" View="{DynamicResource ViewBase1}" />
<ListView Grid.Row="3" ItemsSource="{Binding TuesdayList}" SelectedItem="{Binding CurrentToDo,Mode=TwoWay}" SelectionMode="Single" ItemContainerStyle="{DynamicResource ListViewItemStyleToDo}" View="{DynamicResource ViewBase1}" /> …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中有TextBlocks和Comboboxes我希望Textblock前景为白色,Combobox前景为Black.
我尝试的是:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="White" />
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Foreground" Value="Red" />
</Style>
</ResourceDictionary>
<Grid Background="Black">
<TextBlock Height="23" HorizontalAlignment="Left" Margin="27,30,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" />
<ComboBox Height="23" HorizontalAlignment="Left" Margin="12,99,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" />
</Grid>
Run Code Online (Sandbox Code Playgroud)
但是组合框前景仍然是白色如何覆盖组合框中的TextBlock前景?(在CSS中这很容易,但在WPF中不知道)
如果我删除TextBlock的样式,其他所有内容都会改变,但是当我把样式放回去时,每个前景都是白色的.