(二十一)算法界面

1.导入Png图标以BitmapImage显示

先添加图标
阿里巴巴iconfont
添加到UI的图标包
image
创建资源字典:bitmapsource类型的就可以绑定到前端
image
类的图标名称填好
image
此时传到前台页面的是一个字符串,字符换转图标需要定义转换器
image
在UI层创建转换器
image
在资源字典中对转换器进行实例化
image
在通用资源字典中引入转换器和icon,即放到APP入口文件资源中
image
此时启动则可以看到图标

2.添加索贝尔算法,演示opencv中的函数调用

创建算法模型实体

image

前台页面和vm

image
image

弹出窗体业务逻辑

弹出窗展示了各种算法,我们可以添加算法到操作中,点击提交
image
算法实体模型以对话框参数,键值对的形式传递给流程模块
image

3.反应式编程实战讲解观察者模式用法

添加算法到弹窗外

image

这里需要先创建流程模型,在注入ioc容器中后实例化
image
接口放在share中
image
通过构造函数注入
image

建立前台绑定
image

反应式

点击左侧listbox的子项会把具体的设置导航到右边区域,通常会在切换子项的事件中做

而现在selectitem会随着点击发生变化,所以只要观察他的变化就行,这样就不需要做listbox事件转命令的写法

订阅事件

image
当FlowModel发生变化时,其实就是绑定的选中项变化,做一个响应-->导航事件
image

checkbox样式

image

4.反应式编程-合并多个观察者对象

需求:选中算法时,对图片进行相应的处理
图像算法的提供者
image
DoFilters需要调用IFlowModel中的Filters-->让FlowModel同时继承本接口

具体实现

image

image

合并观察者
image
本类的观察者观察两个参数
image
遍历算法并处理图像
image

补充

ControlTemplate和ItemTemplate的区别

ControlTemplate是指控件的样式
ItemTemplate是指可绑定泛型的控件内容的样式

即只有那些有item的控件才有ItemTemplate(如ListBox ,Combox,TreeView,DataGrid,TabelControl等,),但是所有控件都有ControlTemplate

silverlight的控件大概派生于两种类。一种是contentcontrol类(例如按钮控件),另一种是itemscontrol(例如listbox控件,这种控件可以实现项目集合)。由于contentcontrol类提供了contenttemplate属性,所以可以采用controltemplate自定义控件的内容.如下代码

<Button>
        <Button.Template>
            < ControlTemplate>
                <Grid>
                    < Rectangle Fill="LightBlue" Stroke="Black" StrokeThickness="5"
                              RadiusX="20" RadiusY="20"/>
                    < TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
                        I'm a CT
                    </TextBlock>
                </Grid>
            </ControlTemplate>
        < /Button.Template>
    </Button>

对于listbox这类控件可以使用itemtemplate来自定义控件的外观
使用 ItemTemplate 属性来指定数据的直观表示形式。同时使用 DataTemplate 来定义数据对象的外观。例如下面代码:

<ListBox  ItemsSource="{StaticResource customers}" Width="350" Margin="0,5,0,10">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    < TextBlock Padding="5,0,5,0"
              Text="{Binding FirstName}"  />
                    <TextBlock Text="{Binding LastName}" />
                    <TextBlock Text=", " />
                    < TextBlock Text="{Binding Address}" />
                < /StackPanel>
            </DataTemplate>
        < /ListBox.ItemTemplate>
   </ListBox>

DataTemplate

image
image
原文:
https://www.cnblogs.com/MichaelLoveSna/p/14447919.html
https://www.cnblogs.com/zhangtao/archive/2011/04/09/2010657.html

posted @ 2024-01-17 16:00  huihui不会写代码  阅读(88)  评论(0)    收藏  举报