小编And*_*dyC的帖子

@ Html.Raw坚持编码引号

MVC4剃刀视图.鉴于字符串backgroundImage设置如下:

backgroundImage = string.Format("background: url('{0}') top left no-repeat;", project.MainImage);
Run Code Online (Sandbox Code Playgroud)

为什么这样呢

<div class="spotlight slide teaser-text" id="@slideId" style="@Html.Raw(backgroundImage)">
Run Code Online (Sandbox Code Playgroud)

生产

<div class="spotlight slide teaser-text" id="spotlight-0" style="background: url(&#39;/media/215/spotlight01.jpg&#39;) top left no-repeat;">
Run Code Online (Sandbox Code Playgroud)

Html.Raw,new MvcHtmlStringMvcHtmlString.Create所有的行为类似.

希望它能产生

<div class="spotlight slide teaser-text" id="spotlight-0" style="background: url('/media/215/spotlight01.jpg') top left no-repeat;">
Run Code Online (Sandbox Code Playgroud)

(注意引号).

razor asp.net-mvc-4

8
推荐指数
1
解决办法
2004
查看次数

如何预渲染视图?

我的ViewModel根据用户单击选择一个视图。其中一个视图包含许多可视元素-带有数据模板的视图模型包含带有数据模板的视图模型,每个视图都使用背景imagebrush在画布上渲染。完整视图以大约100个这些画布笔刷结束,每个画布笔刷都叠加有十二个椭圆,整个视图位于一个可滚动的视图框中。

首次创建此视图时,用户单击它,然后在全部渲染后会徘徊一段时间。我想更早地完成此渲染-例如在启动过程中。我已经创建了视图对象,但是当用户单击时,渲染完成后我们仍然在徘徊。

有什么方法可以让WPF / xaml进行预渲染,从而使点击响应更好?

wpf xaml

5
推荐指数
1
解决办法
1271
查看次数

将图表LegendItem复选框绑定到WPF中的系列可见性

我的WPFToolKit图表包含几个系列.我已经模仿了传说本身,并通过创建样式资源模板化LegendItem:

<Style x:Key="CustomLegendItemStyle" TargetType="{x:Type charting:LegendItem}">
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type charting:LegendItem}">
                <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                    <DockPanel LastChildFill="True">
                        <Ellipse Width="10" Height="10" Fill="{Binding Background}" Stroke="{Binding Background}" StrokeThickness="1" Margin="0,0,3,0" DockPanel.Dock="Left"/>
                        <CheckBox IsChecked="{Binding Path=Visibility,Converter={StaticResource VisToBoolConverter},Mode=TwoWay}" />
                        <TextBlock DockPanel.Dock="Right" Text="(num)" />
                        <datavis:Title Content="{TemplateBinding Content}" Margin="10 0" />
                    </DockPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type charting:LineSeries}">
    <Setter Property="LegendItemStyle" Value="{StaticResource CustomLegendItemStyle}" />
</Style>
Run Code Online (Sandbox Code Playgroud)

这会在LegendItem中创建一个复选框,该复选框应该控制系列的可见性.但事实并非如此.我也在ViewModel上创建了属性(默认为true/visible),以及LineSeries可见性绑定到的属性

<charting:LineSeries ... Visibility="{Binding DisplayLoad,Converter={StaticResource BoolToVisConverter},Mode=TwoWay}" />
Run Code Online (Sandbox Code Playgroud)

但这两个人并没有挂钩.如果我将复选框绑定路径更改为StoopidUser,我会在输出窗口中收到绑定错误,告诉我在对象上找不到StoopidUser属性LineDataPoint,这让我有点难过.我已经检查过,无法看到(a)为什么它是一个LineDataPoint(b)如何从它获得系列.

你能看出什么是错的吗?

wpf charts xaml mvvm wpftoolkit

4
推荐指数
1
解决办法
2680
查看次数

WPF弹出窗口选择基于数据绑定类型的模板

有一个包含大量对象的视图,它们从DataTemplate声明中获取它们的视图:

<DataTemplate DataType="{x:Type vm:StatusAViewModel}" >
    <vw:StatusAView />
</DataTemplate>

<DataTemplate DataType="{x:Type vm:StatusBViewModel}" >
    <vw:StatusBView />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

现在我想根据要包含的数据类型显示一个包含其内容的弹出窗口:

<Popup AllowsTransparency="True"
       IsOpen="{Binding IsPopupOpen,Mode=OneWay}" 
       PlacementTarget="{Binding PopupPlacementElement}" Placement="{Binding PopupPlacementMode}"
       HorizontalOffset="{Binding PopupHOffset}" VerticalOffset="{Binding PopupVOffset}">
    <ContentPresenter x:Name="StuckHere" Content="{Binding PopupData}" />
</Popup>
Run Code Online (Sandbox Code Playgroud)

StuckHere上的ContentTemplateSelector不起作用,因为它只被评估一次,当PopupData发生更改时,不会重新选择模板.

我可以找到的所有示例都依赖于默认的datatemplate,我不能在我的情况下使用,因为我已经为主视图提供了默认的DataTemplate,我只希望这个不同的模板影响我的弹出窗口.

有线索吗?

wpf xaml mvvm

2
推荐指数
1
解决办法
2845
查看次数

如何将具有多个连接的Linq表达式转换为方法语法或检索选择索引?

我有一个(工作!)linq表达式:

from ca in db.CustomAnswer
join ss in db.SurveySubmission on ca.SubmissionId equals ss.Id
join cq in db.CustomQuestion on ca.QuestionId equals cq.Id
where (ss.SurveyId == request.SurveyId)
orderby ss.Submitted, cq.SortOrder
select new
{
    SubmissionId = ss.Id,
    Answer = ca.Answer
}
Run Code Online (Sandbox Code Playgroud)

我想将select的索引添加到新对象中,例如

from ca in db.CustomAnswer
join ss in db.SurveySubmission on ca.SubmissionId equals ss.Id
join cq in db.CustomQuestion on ca.QuestionId equals cq.Id
where (ss.SurveyId == request.SurveyId)
orderby ss.Submitted, cq.SortOrder
select new
{
    SubmissionId = ss.Id,
    **Code = selectIndex,**
    Answer = ca.Answer
}
Run Code Online (Sandbox Code Playgroud)

为此,我相信我需要先将查询转换为方法语法,以便我可以使用该 …

c# linq lambda

1
推荐指数
1
解决办法
193
查看次数

标签 统计

wpf ×3

xaml ×3

mvvm ×2

asp.net-mvc-4 ×1

c# ×1

charts ×1

lambda ×1

linq ×1

razor ×1

wpftoolkit ×1