小编yTo*_*ide的帖子

Blazor 获取 div 位置/坐标

我正在创建一个弹出组件,我希望它是可移动的。我可以使用顶部/左侧样式移动它,但现在它们被初始化top:0;left:0;,因此弹出窗口出现在页面的左上角。我希望让它出现在页面的中心,然后获取我的 div 的左上角坐标,以便在之后正确管理我的计算。

这是我现在所拥有的:

<div class="child-window" draggable="true" style="position:absolute; top: @(offsetY)px; left: @(offsetX)px; border-color: black;" @ondragend="OnDragEnd" @ondragstart="OnDragStart">
   <div class="cw-content">
      @Content
   </div>
</div>

@code {
   private double startX, startY, offsetX, offsetY;

   protected override void OnInitialized() {
        base.OnInitialized();
        ResetStartPosition();
    }

   private void ResetStartPosition() {
        //Set offsetX & offsetY to the top left div position
    }

   private void OnDragStart(DragEventArgs args) {
        startX = args.ClientX;
        startY = args.ClientY;
    }

    private void OnDragEnd(DragEventArgs args) {
        offsetX += args.ClientX - startX;
        offsetY += args.ClientY - …
Run Code Online (Sandbox Code Playgroud)

css c# razor asp.net-core blazor

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

Reflection blazor - 获取属性名称+值

在我的父组件上我有这个:

<TestComponent @bind-Value="testString" />

@code {
    [MaxLength(10)]
    private string testString;
}
Run Code Online (Sandbox Code Playgroud)

关于我的TestComponent这个:

<input type="text" @bind="Value" @bind:event="oninput" />

@code {
    [Parameter] public string Value { get; set; }
    [Parameter] public EventCallback<string> ValueChanged { get; set; }

    protected override void OnInitialized() {
        //Get MaxLength here
    }
}
Run Code Online (Sandbox Code Playgroud)

我如何检查我的TestComponentifValue有 aMaxLength并获取他的值(如果有)?

c# razor asp.net-core blazor

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

blazor 中非布尔值的条件属性

我正在尝试使用复选框系统生成自己的组件,以了解我是否需要该属性(类型int/float等)

<input type="checkbox" @bind="isMinInt" />
@if (isMinInt == true) {
    <input type="number" @bind="MinInt"/>
}
Run Code Online (Sandbox Code Playgroud)

所以我想替换这个@if

@if(isMinInt == true) {
    <MyComponent @bind-Value="ValueInt" Min="@MinInt"/>
} else {
    <MyComponent @bind-Value="ValueInt"/>
}
Run Code Online (Sandbox Code Playgroud)

通过类似的东西

<MyComponent @bind-Value="ValueInt" 
             @if(isMinInt == true ? Min="@MinInt" : String.Empty />
Run Code Online (Sandbox Code Playgroud)

因为我的组件上会有很多属性,我想让它更简单

编辑+解决方案

现在使用@attributes

<input type="checkbox" @bind="isMinInt" />
@if (isMinInt == true) {
   <input type="number" @bind="MinInt" />
}

<MyComponent @bind-Value="ValueInt" @attributes="GetAttributesInt()" />

@code {
    private bool isMinInt = false;
    private int MinInt;

    private IDictionary<string, …
Run Code Online (Sandbox Code Playgroud)

asp.net-core blazor

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

未加载 Blazor 组件库中的 CSS

我想使用我的文件中的wwwroot/css/.自定义CSS,BlazorControllers/Components/.但在执行时没有加载任何内容。在客户端或 lib 项目设置中有什么要指定的吗?

我的库项目是BlazorControllers,我在客户端项目中使用库的组件

在此处输入图片说明

razor asp.net-core blazor

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

标签 统计

asp.net-core ×4

blazor ×4

razor ×3

c# ×2

css ×1