在Silverlight 2中,我使用的是usercontrol,它继承了它所嵌入的页面的datacontext.此datacontext包含问题文本,问题类型和答案集合.在用户控件中是一个列表框,它绑定到答案集合.如下所示:
<ListBox DataContext="{Binding}" x:Name="AnswerListBox" ItemContainerStyle="{StaticResource QuestionStyle}" Grid.Row="1" Width="Auto" Grid.Column="2" ItemsSource="{Binding Path=AnswerList}" BorderBrush="{x:Null}" />
Run Code Online (Sandbox Code Playgroud)
此列表框具有相关的样式,以单选按钮或复选框的形式显示答案(我想根据问题类型隐藏或显示):
<Style TargetType="ListBoxItem" x:Key="QuestionStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<StackPanel Background="Transparent" >
<RadioButton Visibility="{Binding Path=QuestionType, Converter={StaticResource QuestionTypeConverter}, ConverterParameter='RadioButtonStyle'}" Height="auto" Margin="0,0,0,10" IsChecked="{TemplateBinding IsSelected}" IsHitTestVisible="False" Content="{Binding Path=AnswerText}">
</RadioButton>
<CheckBox Visibility="{Binding Path=QuestionType, Converter={StaticResource QuestionTypeConverter}, ConverterParameter='CheckBoxStyle'}" Height="auto" Margin="0,0,0,10" Content="{Binding Path=AnswerText}">
</CheckBox>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
那么我的问题是:如何访问父数据上下文以获取QuestionType(因为这是用户控件datacontext本身的属性,而不是AnswerList中AnswerItem上的属性)?
或者,有没有更好的方法根据绑定值在xaml中动态切换样式?
有没有办法在没有安装MS Word的情况下打印OOXML文档(.docx文件)?
它通过MS Word界面很好地工作,但我需要找到一种方法在没有安装MS Word的服务器上使用它.我一直在挖掘API并且没有找到任何明显的东西,所以我倾向于认为没有办法.是这样的吗?
编辑:德文的答案基本上就是我所理解的情况.我应该提到我正在使用.NET框架.所以我想知道是否有一个.NET库可以处理一个docx文件进行打印?我看到当DefaultPrinterQueue在一个LocalPrintServer(在System.Printing命名空间中)添加一个作业时,它可以处理一个XPS文档.所以也许这就是要走的路.