首页 > 其他分享 >wpf 使用razor

wpf 使用razor

时间:2024-08-11 11:05:29浏览次数:5  
标签:razor WPFBlazorChat System CPU 使用 Release using wpf Any

WPFBlazorChat\RazorViews\Counter.razor

<h1>Counter</h1>

<p>好开心,你点我了,现在是:<span style="color: red;">@currentCount</span></p>

<button class="btn btn-primary" @onclick="IncrementCount">快快点我</button>

@code {

    
    private int currentCount = 0;

    private void IncrementCount()
    {
        currentCount++;
    }

}

WPFBlazorChat\App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace WPFBlazorChat
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

    }

}



WPFBlazorChat\MainWindow.xaml.cs

using Microsoft.Extensions.DependencyInjection;
using System.Windows;

namespace WPFBlazorChat;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        var serviceCollection = new ServiceCollection();
        serviceCollection.AddWpfBlazorWebView();
        Resources.Add("services", serviceCollection.BuildServiceProvider());
    }
}


WPFBlazorChat\MainWindow.xaml

<Window x:Class="WPFBlazorChat.MainWindow"
        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:blazor="clr-namespace:Microsoft.AspNetCore.Components.WebView.Wpf;assembly=Microsoft.AspNetCore.Components.WebView.Wpf"
        xmlns:local="clr-namespace:WPFBlazorChat"
        xmlns:razorViews="clr-namespace:WPFBlazorChat.RazorViews"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <blazor:BlazorWebView HostPage="wwwroot\index.html" Services="{DynamicResource services}">
            <blazor:BlazorWebView.RootComponents>
                <blazor:RootComponent Selector="#app" ComponentType="{x:Type razorViews:Counter}" />
            </blazor:BlazorWebView.RootComponents>
        </blazor:BlazorWebView>
    </Grid>
</Window>


WPFBlazorChat\wwwroot\css\app.css

html, body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

h1:focus {
    outline: none;
}

a, .btn-link {
    color: #0071c1;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid red;
}

.validation-message {
    color: red;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

WPFBlazorChat\wwwroot\index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>WPFBlazorChat</title>
    <base href="/" />
    <link href="css/app.css" rel="stylesheet" />
    <link href="WpfBlazor.styles.css" rel="stylesheet" />
</head>

<body>
<div id="app">Loading...</div>

<div id="blazor-error-ui">
    An unhandled error has occurred.
    <a href="" class="reload">Reload</a>
    <a class="dismiss">

标签:razor,WPFBlazorChat,System,CPU,使用,Release,using,wpf,Any
From: https://www.cnblogs.com/zhuoss/p/18353175

相关文章

  • wpf项目如何使用blazor组件
    依然使用上面的工程,添加Blazor支持,此部分参考微软文档生成WindowsPresentationFoundation(WPF)Blazor应用,本小节快速略过。2.1编辑工程文件WPFBlazorChat.csproj在项目文件的顶部,将SDK更改为Microsoft.NET.Sdk.Razor。添加节点<RootNameSpace>WPFBlazorChat</RootN......
  • 掌握 Nuxt 3 的页面元数据:使用 definePageMeta 进行自定义配置
    title:掌握Nuxt3的页面元数据:使用definePageMeta进行自定义配置date:2024/8/11updated:2024/8/11author:cmdragonexcerpt:摘要:本文详细介绍Nuxt3框架中definePageMeta的使用方法,包括如何为页面组件定义元数据,如布局、过渡效果、路由中间件等。通过具体示例展示......
  • Python使用PyCharm创建一个简单的Qt Quick应用程序-hello_world_quick.py(读取qml文件
    """CreateaSimpleQuickApplication"""importsysfrompathlibimportPathfromPySide6.QtGuiimportQGuiApplicationfromPySide6.QtQmlimportQQmlApplicationEngine#打开文件,读取文件,并返回文件内容defread_file(file_path):"......
  • 简单在 WinUI 仿造 WPF 的 ColumnDefinition SharedSizeGroup 共享列宽功能
    本文将告诉大家如何在WinUI3或UNO里面,仿造WPF的ColumnDefinitionSharedSizeGroup共享列宽功能本文的实现代码是大量从https://github.com/Qiu233/WinUISharedSizeGroup抄的,感谢大佬提供的代码。我在此基础上简化了对Behavior的依赖,在本文末尾放上了全部代码的下载......
  • Python使用PyCharm创建一个简单的Qt Widgets应用程序-hello_world.py
    """CreateaSimpleQtWidgetsApplication"""importrandomimportsysfromPySide6importQtCore,QtWidgets#MainClassclassMyWidget(QtWidgets.QWidget):def__init__(self):super().__init__()self......
  • Docker简单使用MySQL
    前提安装好Docker下载Mysql镜像在这个网址搜索Mysql并选择合适的镜像https://hub.atomgit.com/详情页就有拉取镜像的命令查看Docker所有镜像​ dockerimages镜像重命名​ dockertag镜像id仓库:标签​ dockertag8a709252ac32mysql:5.7镜像启动(容器)dockerrun......
  • Python使用PyCharm创建一个简单的Qt Quick应用程序-hello_world_quick.py
    """CreateaSimpleQuickApplication"""importsysfromPySide6.QtGuiimportQGuiApplicationfromPySide6.QtQmlimportQQmlApplicationEngineQML="""importQtQuickimportQtQuick.ControlsimportQtQuick.Lay......
  • 使用Pinata在IPFS上存储NFT图片的实践
    文章目录前言一、什么是IPFS?二、为什么NFT需要IPFS?三、Pinata:IPFS上的存储解决方案四、实践:使用Pinata存储NFT图片1.注册2.获取API密钥与网关3.上传图片到IPFS总结前言随着区块链技术的快速发展,NFT(非同质化代币)在数字艺术、游戏和收藏品等领域变得越来越流行......
  • 在Spring Boot应用中配置和使用MinIO
    要在SpringBoot项目中使用MinIO作为对象存储服务,可以使用MinIO的JavaSDK来与MinIO进行交互。以下是如何在SpringBoot应用中配置和使用MinIO的详细步骤:1.添加MinIO依赖首先,你需要在项目中添加MinIO的JavaSDK依赖。如果使用的是Maven,添加以下依赖到pom.xml中:<dependency>......
  • Github-vscode联合使用保姆及教程
    Github-VScode联合使用保姆及教程update:2024/8/10_Karenbluu文章目录Github-VScode联合使用保姆及教程1.Git和Github分别是什么2.安装2.1git安装2.2vscode安装3.使用Github3.1拉取项目3.1.1拉取方法3.1.2注意事项3.2寻找合适的项目3.3创建自己的git......