小编Khu*_*shi的帖子

TextBlock,其中一些文本左对齐,其余文本右对齐

我想要一个包含以下文本的文本块:

My associated textbox is                :
Run Code Online (Sandbox Code Playgroud)

文本左对齐,冒号右对齐.

我知道如何使用两个文本块获得上述输出.但我想知道适用于单个文本块的行为是否相同?

c# wpf xaml

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

在TextBlock中加入文本的一部分

我知道我们可以<Run>在XAML中使用来实现我的要求:

<TextBlock.Inlines>
    <Run Text="This is" />
    <Run FontWeight="Bold" Text="Bold Text." />
</TextBlock.Inlines>
Run Code Online (Sandbox Code Playgroud)

我也可以在代码后面执行如下操作:

TextBlock.Inlines.Add(new Run("This is"));
TextBlock.Inlines.Add(new Bold(new Run("Bold Text.")));
Run Code Online (Sandbox Code Playgroud)

但我的问题有所不同:

假设我的数据库中有以下Text:

This is <b>Bold Text</b>.
Run Code Online (Sandbox Code Playgroud)

现在,我的Textblock绑定到一个包含数据库中上述文本的字段.

我想要的text between <b> and </b> to be bold.我怎样才能做到这一点?

c# wpf xaml

7
推荐指数
2
解决办法
9710
查看次数

使用div标签将页面分为三个部分

我试图让以下布局超过1.5小时但仍然无法获得正确的解决方案.

好吧,如果有任何重复,那么请原谅我提出这个问题.

我想使用div标签有如下图所示的布局:

| _ __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ __ | | | | | | | | | | | | | | _ __ _ …

html layout

4
推荐指数
2
解决办法
9万
查看次数

删除附加到ajax请求返回的结果中的自动生成的广告脚本

我的网站托管在somee.com上。

我已经使用JQuery发送Ajax请求。

在每个ajax请求中,返回的结果将附加以下文本。

"<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE--> 
<center><a href="http://somee.com">Web hosting by Somee.com</a></center> </textarea>
</xml></script></noframes></noscript></object></layer></style></title></applet> 
<script language="JavaScript" 
src="http://ads.mgmt.somee.com/serveimages/ad2/WholeInsert4.js"></script>
<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->"
Run Code Online (Sandbox Code Playgroud)

例如,如果成功调用ajax,服务器将返回以下字符串:“无效的用户名和/或密码”

然后我得到以下字符串:

"Invalid Username and/or Password <!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->
 <center><a href="http://somee.com">Web hosting by Somee.com</a></center> </textarea>
</xml></script></noframes></noscript></object></layer></style></title></applet> 
<script language="JavaScript" 
src="http://ads.mgmt.somee.com/serveimages/ad2/WholeInsert4.js"></script> 
<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->"
Run Code Online (Sandbox Code Playgroud)

现在,我将这个字符串与另一个字符串进行比较,因此比较返回false,因为此字符串包含附加的文本。

因此,我的网站无法正常运行。

编辑

我数了。字符并尝试使用.slice(0, -no. of characters in advertisement)。如果服务器返回字符串,则可以正常工作。但是在服务器返回时不起作用,'JSON'因为在ajax调用中我们必须声明dataType:'json',添加广告脚本后,结果将不再是json对象。因此,没有调用成功,因此我没有得到输出。

所以,现在我的问题是:如果服务器JSON + String在AJAX调用上返回,则在客户端,我只想delete the String part获取 …

ajax jquery ads

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

使用MVVM模式将数据添加到数据库

我正在尝试将数据保存到数据库.

假设我有一个名为Customers三个字段的表:

Id
FirstName
LastName
Run Code Online (Sandbox Code Playgroud)

我使用ADO.Net实体数据模型创建了我的模型.

这是我的ViewModel代码

public class myViewModel : INotifyPropertyChanged
{
    private string _firstName;
    public string FirstName
    {
        get
        {
            return _firstName;
        }
        set
        {
            _firstName = value;
            OnPropertyChanged("FirstName");
        }
    }

    private string _lastName;
    public string LastName
    {
        get
        {
            return _lastName;
        }
        set
        {
            _lastName = value;
            OnPropertyChanged("LastName");
        }
    }

    protected virtual void OnPropertyChanged(string PropertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(PropertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

} …
Run Code Online (Sandbox Code Playgroud)

c# silverlight wpf xaml mvvm

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

类似于 XAML 中的 For 循环

我有一个资源字典,我想在其中为 ComboBox 提供一个通用的 DataTemplate。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <DataTemplate DataType="{x:Type ComboBox}">
        <StackPanel Orientation="Horizontal">
            <!--Here I need to use something like For Loop-->
            <TextBlock Text=""></TextBlock>
        </StackPanel>
    </DataTemplate>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

现在我创建了一个名为 NoOfColumns 的整数类型的依赖属性。在声明组合框时,我需要设置 NoOfColumns 属性以自动生成该数量的列。我想让他们databind

应乔的要求更新

<ComboBox x:Name="cbUnder" ItemsSource="{Binding GroupsAndCorrespondingEffects}" 
    IsEditable="True" SelectedItem="{Binding SelectedGroup, Mode=TwoWay}" 
    Text="{Binding InputValue, UpdateSourceTrigger=PropertyChanged}" TextSearch.TextPath="GroupName" 
    Grid.Column="1" Grid.ColumnSpan="4" Grid.Row="3">
    <ComboBox.Resources>
        <DataTemplate DataType="{x:Type vm:GroupAndCorrespondingEffect}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding GroupName}" Width="250">
                    <TextBlock.Style>
                        <Style TargetType="TextBlock">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsHighlighted}" Value="True">
                                    <Setter Property="Foreground" Value="Blue" />
                                    <Setter Property="FontWeight" Value="Bold"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>
                <TextBlock …
Run Code Online (Sandbox Code Playgroud)

wpf xaml

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

如何在 WPF MVVM 中使用外键绑定组合框

我知道有很多关于 DataBinding 组合框的问题,也有很多教程,但我觉得这些教程很难。所以,我问这个问题。

假设我的数据库中有两个表:

顾客

CustomerID
Name
GenderID
Run Code Online (Sandbox Code Playgroud)

性别类型

GenderTypeID
GenderType
Run Code Online (Sandbox Code Playgroud)

我已经使用 ADO.Net 实体数据模型创建了我的模型。所以,我正在使用实体框架。

现在我有一个 ViewModel,我在其中声明了一个名为 Customers 的属性,如下所示:

private List<Customer> _customers;
public List<Customer> Customers
{
    get
    {
        return _customers;
    }
    set
    {
        _customers = value;
        OnPropertyChanged("Customers");
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我有一个这样的视图:

<Window ......>

    <Window.DataContext>
        <vm:MainWindowViewModel />
    </Window.DataContext>

    <Grid>
        <Grid.RowDefinitions>
            ..
            ..
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            ..
            ..
        </Grid.ColumnDefinitions>

        <TextBlock Text="Name" ....../>
        <TextBox Text="{Binding Name}"...../>

        <TextBlock Text="Gender" ....../>
        <TextBox ItemsSource="????"
                 SelectedValue="????"
                 SelectedValuePath="????"...../>

    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

我不知道如何绑定组合框,这样我就可以看到男性和女性作为组合框的项目,当我选择时,我应该得到相应的 GenderID 而不是 GenderType。

我知道这是一个非常简单和直接的问题,但我对 WPF 非常陌生并试图学习它。

c# silverlight wpf xaml mvvm

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

获取我点击过/ mousedown的元素的名称

我有一个页面,其根元素是名为的网格Root

我像许多控件TextBlockTextBoxGridRectangleBorder等...谁是孩子Root

现在,我想有一个MouseDownPreviewMouseDownClickRoot找到关于这一点我点击的元素的名称。

所以,我怎么能得到的元素,我的名字clicked/ mousedown

如果我可以获得使用隧道的解决方案,那将容易得多。

c# wpf xaml

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

在wpf中静态属性更改时收到通知

这里微软描述了在wpf 4.5中我们也可以使用INotifypropertyChanged来获取静态属性.所以我试着这样做.

这是代码:

public static event PropertyChangedEventHandler StaticPropertyChanged;
    protected static void OnStaticPropertyChanged(string PropertyName)
    {
        PropertyChangedEventHandler handler = StaticPropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(PropertyName));
        }
    }
Run Code Online (Sandbox Code Playgroud)

但我不知道this在上面的代码中使用什么而不是关键字?

这是我的代码:

public static event PropertyChangedEventHandler StaticPropertyChanged;
protected static void OnStaticPropertyChanged(string PropertyName)
{
    PropertyChangedEventHandler handler = StaticPropertyChanged;
    if (handler != null)
    {
        handler(typeof(MainWindowViewModel), new PropertyChangedEventArgs(PropertyName));
    }
}

private static Haemogram _cHaemogram;
public static Haemogram cHaemogram
{
    get
    {
        return _cHaemogram;
    }
    set
    {
        _cHaemogram = value;
        OnStaticPropertyChanged("cHaemogram");
    }
}
Run Code Online (Sandbox Code Playgroud)

c# wpf

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

用列表中的另一个字母替换字母

我有一份清单

List<string> myList = new List<string>();
myList.Add("A");
myList.Add("B");
myList.Add("C");
...
...
...
myList.Add("Z");
Run Code Online (Sandbox Code Playgroud)

现在我想替换A with N,B with Xso on..........

我知道有Replace(string, string).

但有没有简单的方法呢?

c#

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

如何获取硬盘序列号?

目前我使用以下代码获取硬盘的序列号:

private void GetAllDiskDrives()
{
    var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

    foreach (ManagementObject wmi_HD in searcher.Get())
    {
        HardDrive hd = new HardDrive();
        hd.Model = wmi_HD["Model"].ToString();
        hd.InterfaceType = wmi_HD["InterfaceType"].ToString();
        hd.SerialNo = wmi_HD.GetPropertyValue("SerialNumber").ToString();//get the serailNumber of diskdrive
        HdCollection.Add(hd);
    }
}

public class HardDrive
{
    public string Model { get; set; }
    public string InterfaceType { get; set; }
    public string SerialNo { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常.

但上面的代码返回所有驱动器.我只想要运行我的软件的特定硬盘驱动器(Not Partition)序列号.

那么,如何获取运行我的软件的硬盘序列号?

c# wmi

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

将TextBox的Text属性绑定到TextBlock的附加属性,如Grid.Row

假设我有两个元素.可以说,

  1. TextBlock的
  2. 文本框

现在,如果我想将TextBox的Text绑定到TextBlock的Text,我可以执行以下操作:

<TextBox Text="{Binding Text, ElementName=someTextBlock}" />
Run Code Online (Sandbox Code Playgroud)

现在,如果我的TextBlock在Grid中,如下所示:

<Grid>
    <TextBlock Text="someText" Grid.Row=1 Grid.Column=2 />
</Grid>
Run Code Online (Sandbox Code Playgroud)

现在我的问题是如何将TextBox的Text绑定到Grid.Row或Grid.Column?

我的意思是

<TextBox Text={Binding Grid.Row, ElementName=someTextBlock} />
Run Code Online (Sandbox Code Playgroud)

上面的代码不起作用.

我知道我在这里做错了什么.

c# wpf xaml

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

我的申请变得很慢

我有大约15个属性的每个控件绑定到数据库.

我的应用程序需要提供可以由客户端设置的Horizo​​ntalAlignment,VerticalAlignment,Margin,Background,Foreground,...........等属性.因此,我在数据库中创建了一个表,以便在客户端设置它们时保存这些属性的值.我在ViewModel的构造函数中检索该属性的值.

但是当我的应用程序运行时,它需要7到8分钟才能完全启动.

以下是我的代码的一小部分示例:

XAML

<TextBlock Grid.Row="{Binding HaemogramRowHaemoglobinTest}" Grid.Column="{Binding HaemogramColumnHaemoglobinTest}"
           Grid.RowSpan="{Binding HaemogramRowSpanHaemoglobinTest}" Grid.ColumnSpan="{Binding HaemogramColumnSpanHaemoglobinTest}"
           Text="{Binding HaemogramTextHaemoglobinTest}" 
           Visibility="{Binding HaemogramVisibilityHaemoglobinTest, Converter={StaticResource booleanToVisibilityConverter}}"
           Background="{Binding HaemogramBackgroundHaemoglobinTest, Converter={StaticResource colorNameToSolidColorBrushConverter}}" 
           Foreground="{Binding HaemogramForegroundHaemoglobinTest, Converter={StaticResource colorNameToSolidColorBrushConverter}}"
           FontFamily="{Binding HaemogramFontNameHaemoglobinTest, Converter={StaticResource stringToFontFamilyConverter}}" 
           FontSize="{Binding HaemogramFontSizeHaemoglobinTest}"
           FontWeight="{Binding HaemogramFontBoldHaemoglobinTest, Converter={StaticResource booleanToBoldConverter}}" 
           FontStyle="{Binding HaemogramFontItalicsHaemoglobinTest, Converter={StaticResource booleanToItalicsConverter}}"
           TextDecorations="{Binding HaemogramFontUnderlineHaemoglobinTest, Converter={StaticResource booleanToUnderlineConverter}}"
           HorizontalAlignment="{Binding HaemogramHorizontalAlignmentHaemoglobinTest, Converter={StaticResource intToHorizontalAlignmentConverter}}" 
           VerticalAlignment="{Binding HaemogramVerticalAlignmentHaemoglobinTest, Converter={StaticResource intToVerticalAlignmentConverter}}"
           Margin="{Binding HaemogramMarginHaemoglobinTest}" >
Run Code Online (Sandbox Code Playgroud)

视图模型

public MainWindowViewModel()
{
    using (Lab_Lite_Entities db = new Lab_Lite_Entities())
    {
        HaemogramRowTest = db.Designs.Where(d => d.MasterPage.Value == "Haemogram Report" && d.FieldName == "Test").Select(d …
Run Code Online (Sandbox Code Playgroud)

c# wpf entity-framework

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

标签 统计

c# ×10

wpf ×9

xaml ×7

mvvm ×2

silverlight ×2

ads ×1

ajax ×1

entity-framework ×1

html ×1

jquery ×1

layout ×1

wmi ×1