I have a usercontrol which has a couple of textblocks on it
<UserControl x:Class="Tester.Messenger"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
x:Name="myUserControl"
>
<TextBlock Text="{Binding ElementName=myUserControl,Path=Header,Mode=TwoWay}" Foreground="LightGray" FontSize="11" Margin="3,3,0,-3"/>
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding ElementName=myUserControl,Path=Message, Mode=TwoWay}" Foreground="White" FontSize="16" Margin="3,-5"/>
Run Code Online (Sandbox Code Playgroud)
In my code behind I have two dependency properties that I'm binding the above textblocks Text property to.
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register("HeaderProperty", typeof(string), typeof(UserControl), new PropertyMetadata("header"));
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register("MessageProperty", typeof(string), typeof(UserControl), new PropertyMetadata(null));
public string Header
{ …Run Code Online (Sandbox Code Playgroud) 我有一个查询,它只从 silverlight4 域服务中的实体返回一列。如何将结果转换为列表?
public List<string> GetDataForTags()
{
var result = from d in this.ObjectContext.vwBusinessUnits
select d.BusinessLineID.Distinct();
return result;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用
return result as List<ToList();
Run Code Online (Sandbox Code Playgroud)
和
return result.Cast<string>().ToList();
Run Code Online (Sandbox Code Playgroud)
但我得到一个无法隐式转换类型错误从Generic.IEnumerable<string>到Generic.List<string>
目前我可以使用
var result = from d in this.ObjectContext.vwBusinessUnits
select d.BusinessLineID;
return result.Distinct().ToList();
Run Code Online (Sandbox Code Playgroud)
我正在尝试在视图模型中使用此结果,但出现转换错误
private void LoadBUGroupTags()
{
TagsData = SecurityDomainContext.Current.GetDataForTags();
}
Run Code Online (Sandbox Code Playgroud)
错误 1 无法将类型“System.ServiceModel.DomainServices.Client.InvokeOperation>”隐式转换为“System.Collections.Generic.List”
和 TagsData 只是一个公共财产
public List<string> TagsData
{
get
{
return _tags;
}
set
{
if (_tags != value)
{
_tags = value;
OnNotifyPropertyChanged("TagsData");
}
} …Run Code Online (Sandbox Code Playgroud) 我定义了一个静态资源:
<UserControl x:Class="MyProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Width="255"
Height="300">
<UserControl.Resources>
<sys:Double x:Key="CornerRadiusValue">5</sys:Double>
</UserControl.Resources>
...
Run Code Online (Sandbox Code Playgroud)
稍后在 XAML 文件中,我尝试在为边框设置左上角半径时使用该值:
<Border
Width="40"
Height="30"
BorderThickness="1,1,0,0"
BorderBrush="Red">
<Border.CornerRadius>
<CornerRadius TopLeft="{StaticResource CornerRadiusValue}" />
</Border.CornerRadius>
</Border>
Run Code Online (Sandbox Code Playgroud)
在设计时,一切正常,更改CornerRadiusValue静态资源的值会更改边框上的角半径。但是,当我想运行它时,我收到一条XamlParseException消息异常:
无法设置只读属性“System.Windows.CornerRadius.TopLeft”。
我究竟做错了什么?我如何使它工作?谢谢。
在 Silverlight/WPF 中使用 MVVM 模式,如何连接事件处理程序?我正在尝试将 XAML Click属性绑定到视图模型中的委托,但无法使其工作。
换句话说,我想替换这个:
<Button Content="Test Click" Click="Button_Click" />
Run Code Online (Sandbox Code Playgroud)
其中 Button_Click 是:
private void Button_Click(object sender, RoutedEventArgs e)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
有了这个:
<Button Content="Test Click" Click="{Binding ViewModel.HandleClick}" />
Run Code Online (Sandbox Code Playgroud)
其中 HandleClick 是处理程序。尝试此操作会引发运行时异常:
“System.Windows.Data.Binding”类型的对象无法转换为“System.Windows.RoutedEventHandler”类型。
我有一个实现 INavigationAware 接口的视图。该接口具有 OnNavigationFrom 方法,即根据 MSDN http://msdn.microsoft.com/en-us/library/microsoft.practices.prism.regions.inavigationaware.onnavigatedfrom(v=pandp.40).aspx,
当实现者被导航离开时调用。
现在,我想确保用户没有留下任何未保存的更改,如果有未保存的更改,请询问用户是否要保存它们。此时,我需要能够以某种方式取消该导航请求,以防用户想留下来继续编辑。
MSDN 上有关 INavigationAware 接口的文档没有说明应该如何使用该接口。
我可能是大错特错了,没有办法取消它,或者这个界面不适合那个。
无论如何,如果有人告诉我如何让用户留下并继续编辑已启动的导航请求,我将不胜感激。
我正在使用 ItextSharp Stamper 加载模板化 PDF,并希望将项目符号列表添加到 PDF 中的特定位置。
拳头这可能吗?我在 mikesdotnetting 博客中看到了如何创建列表,它看起来像我需要的。但是,我想定位列表。
我意识到有很多关于 ItextSharp 的文章和主题,但没有找到任何东西。
谢谢!
我正在开发一个大型解决方案,其中包括 20 个项目(在 silverlight 中,并使用 10 个 wcf 服务),每次都要测试表示层,我必须构建所有解决方案,并且需要更多时间。你有减少构建时间的解决方案吗?
我有什么:
1.XAML中的文本块
2.来自数据库的查询,其中包含DateTime?类型数据.
我的工作:
1.我用DateTime声明一个"myClass"类?
我想要的参数名称为"myDate"
1.在文本块中显示MyDate [我知道]
2.当"myDate"的值为null时,在文本块中显示一个字符串.[我不知道,因为Get方法只能返回DateTime?类型值,但不是字符串类型.]
如何快速开始Windows Phone 7使用streams?
我需要能够从磁盘加载,保存到磁盘,从内存加载,保存到内存文件wp7,但每次我尝试保存,这会发生:
Silverlight is in a sandboxed mode where it has restricted access. You can write to "Isolated Storage", but you cannot create files on their hard drive.
Run Code Online (Sandbox Code Playgroud)
您能否提供一些使用流的工作示例?还有一些教程/视频会很好
我试图在Silverlight/C#中找到一种让DispatchTimer只运行一次的方法.
我有一个用户表单,当提交时我想显示一条消息10秒然后消失并杀死DispatchTimer线程.
我知道如何制作一个重复的DispatchTimer:
clock.Interval = TimeSpan.FromSeconds(10);
clock.Tick += clockTick;
clock.Start();
Run Code Online (Sandbox Code Playgroud)
但我希望该线程一完成就结束.