Silverlight-ComboBox和toolkit:DataForm中的其他字段在.xaml.cs中不可用

时间:2018-10-01 14:17:29

标签: c# model-view-controller silverlight-4.0 silverlight-3.0 silverlight-toolkit

所以基本上我有这个Silverlight应用程序,其中包含一个带组合框的DataForm。我需要去设置它的物品来源等等。

问题在于,表单中的命名字段似乎未在为绑定.xaml.cs和.xaml而创建的自动生成的文件中捕获。

这是我的.xaml的内容,我要影响的组合框是cbDestination

<cc:FlipControl.Rear>
            <toolkit:DataForm Width="620" x:Name="dfStorages" Header="{Binding LocalizationResources.Add, Source={StaticResource ORDictionary}}" CommandButtonsVisibility="Commit, Cancel" CommitButtonContent="{Binding LocalizationResources.Save, Source={StaticResource ORDictionary}}" CancelButtonContent="{Binding LocalizationResources.Cancel, Source={StaticResource ORDictionary}}" EditEnding="dfStorages_EditEnding" CurrentItemChanged="dfStorages_CurrentItemChanged">
                <toolkit:DataForm.NewItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <toolkit:DataField Label="Image">
                                <Grid>
                                    <TextBlock x:Name="lblImageUpload" Text="{Binding LocalizationResources.DropImageMsg, Source={StaticResource ORDictionary}}" Foreground="Gray" IsHitTestVisible="False" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4" Width="92" TextAlignment="Center" TextWrapping="Wrap" />
                                    <Image Source="{Binding Image.Bytes, Mode=TwoWay, Converter={StaticResource ByteToImage}}" Margin="2" Width="96" Height="96" Stretch="Uniform" HorizontalAlignment="Left"/>
                                    <Rectangle x:Name="dropZone" Grid.Row="1" Width="100" Height="100"  Stroke="Gray" StrokeThickness="2" StrokeDashArray="4 2" Fill="Transparent" AllowDrop="True" DragLeave="DropZone_DragLeave" DragOver="DropZone_DragOver" Drop="DropZone_Drop" MouseLeftButtonDown="ImageUpload_MouseLeftButtonDown" HorizontalAlignment="Left" />
                                </Grid>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.Contract, Source={StaticResource ORDictionary}}" IsRequired="True" PropertyPath="ProjectNumber">
                                <TextBox x:Name="tbProjectNumber" Text="{Binding ProjectNumber, Mode=TwoWay}" Width="100" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.ChargeNumber, Source={StaticResource ORDictionary}}">
                                <TextBox Text="{Binding ChargeNumber, Mode=TwoWay}" Width="100" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.PickupLocation, Source={StaticResource ORDictionary}}" IsRequired="True" PropertyPath="PickupLocation">
                                <TextBox Text="{Binding PickupLocation, Mode=TwoWay}" Width="200" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="Destination" IsRequired="True" PropertyPath="Destination">
                                <ComboBox x:Name="cbDestination" Height="24" Width="100" HorizontalAlignment="Left" ItemsSource="{Binding CmbContent}" SelectedItem="{Binding Destination, Mode=TwoWay}">
                                    <ComboBox.ItemContainerStyle>
                                        <Style TargetType="ComboBoxItem">
                                            <Setter Property="Height" Value="22"/>
                                        </Style>
                                    </ComboBox.ItemContainerStyle>
                                </ComboBox>
                            </toolkit:DataField>
                            <toolkit:DataField Label="Type" IsRequired="True" PropertyPath="Type">
                                <ComboBox Height="24" Width="100" HorizontalAlignment="Left" SelectedItem="{Binding Type, Mode=TwoWay}">
                                    <ComboBox.ItemContainerStyle>
                                        <Style TargetType="ComboBoxItem">
                                            <Setter Property="Height" Value="22"/>
                                        </Style>
                                    </ComboBox.ItemContainerStyle>
                                    <System:String>Pallet</System:String>
                                    <System:String>Crate</System:String>
                                    <System:String>Cabinet</System:String>
                                    <System:String>Box</System:String>
                                    <System:String>Barrel</System:String>
                                    <System:String>Other</System:String>
                                </ComboBox>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.Length, Source={StaticResource ORDictionary}, StringFormat='\{0\} (in/po)'}" IsRequired="True" PropertyPath="Length">
                                <TextBox Text="{Binding Length, Mode=TwoWay}" Width="75" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.Width, Source={StaticResource ORDictionary}, StringFormat='\{0\} (in/po)'}" IsRequired="True" PropertyPath="Width">
                                <TextBox Text="{Binding Width, Mode=TwoWay}" Width="75" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.Height, Source={StaticResource ORDictionary}, StringFormat='\{0\} (in/po)'}" IsRequired="True" PropertyPath="Height">
                                <TextBox Text="{Binding Height, Mode=TwoWay}" Width="75" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.DurationMonth, Source={StaticResource ORDictionary}}" IsRequired="True" PropertyPath="MonthPeriod">
                                <TextBox Text="{Binding MonthPeriod, Mode=TwoWay}" Width="75" HorizontalAlignment="Left"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="{Binding LocalizationResources.TotalCost, Source={StaticResource ORDictionary}}" IsReadOnly="True">
                                <Border BorderBrush="Black" BorderThickness="1" Width="100" HorizontalAlignment="Left" Height="23">
                                    <TextBlock Margin="4,0" Text="{Binding TotalCost, Mode=TwoWay}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                </Border>
                            </toolkit:DataField>
                            <toolkit:DataField Label="Description" IsRequired="True" PropertyPath="Comment">
                                <TextBox Text="{Binding Comment, Mode=TwoWay}" Width="350" HorizontalAlignment="Left" AcceptsReturn="True" Height="100" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"/>
                            </toolkit:DataField>
                            <toolkit:DataField Label="Note">
                                <TextBox Text="{Binding Note, Mode=TwoWay}" Width="350" HorizontalAlignment="Left" AcceptsReturn="True" Height="100" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"/>
                            </toolkit:DataField>
                            <toolkit:DataField x:Name="dataFieldDetails" Label="{Binding LocalizationResources.Details, Source={StaticResource ORDictionary}}" >
                                <StackPanel Margin="0,10">
                                    <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                                        <StackPanel Margin="0,5,5,5">
                                            <sdk:Label Content="{Binding LocalizationResources.ItemNumber, Source={StaticResource ORDictionary}}" />
                                            <TextBox Width="100" Text="{Binding ItemNumber, Mode=TwoWay}"/>
                                        </StackPanel>
                                        <StackPanel Margin="0,5,5,5">
                                            <sdk:Label Content="{Binding LocalizationResources.ItemDescription, Source={StaticResource ORDictionary}}" />
                                            <TextBox Width="150" Text="{Binding ItemDescription, Mode=TwoWay}"/>
                                        </StackPanel>
                                        <StackPanel Margin="0,5,5,5">
                                            <sdk:Label Content="{Binding LocalizationResources.Quantity, Source={StaticResource ORDictionary}}" />
                                            <TextBox Width="75" Text="{Binding Quantity, Mode=TwoWay}"/>
                                        </StackPanel>
                                        <StackPanel Margin="0,5,5,5">
                                            <sdk:Label Content="{Binding LocalizationResources.Value, Source={StaticResource ORDictionary}}" />
                                            <TextBox Width="75" Text="{Binding Value, Mode=TwoWay}"/>
                                        </StackPanel>
                                        <Button Margin="0,5,5,5" ToolTipService.ToolTip="{Binding LocalizationResources.Add, Source={StaticResource ORDictionary}}" Height="25" Width="25" Background="Transparent" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="AddDetail_Click">
                                            <Image Source="{Binding LocalizationResources.Image_Add, Source={StaticResource ORDictionary}, Converter={StaticResource ByteToImage}}" Stretch="None"/>
                                        </Button>
                                    </StackPanel>
                                    <sdk:DataGrid HorizontalAlignment="Left" Height="100" Width="450" x:Name="dgStorageDetails" AutoGenerateColumns="False" SelectionMode="Extended" ClipboardCopyMode="None" SelectedIndex="-1">
                                        <sdk:DataGrid.Columns>
                                            <sdk:DataGridTextColumn ch:BindingHelper.HeaderBinding="{Binding LocalizationResources.ItemNumber, Source={StaticResource ORDictionary}}"  Binding="{Binding ItemNumber}" SortMemberPath="ItemNumber" />
                                            <sdk:DataGridTextColumn ch:BindingHelper.HeaderBinding="{Binding LocalizationResources.ItemDescription, Source={StaticResource ORDictionary}}"  Binding="{Binding ItemDescription}" SortMemberPath="ItemDescription" />
                                            <sdk:DataGridTextColumn ch:BindingHelper.HeaderBinding="{Binding LocalizationResources.Quantity, Source={StaticResource ORDictionary}}"  Binding="{Binding Quantity}" SortMemberPath="Quantity" />
                                            <sdk:DataGridTextColumn ch:BindingHelper.HeaderBinding="{Binding LocalizationResources.Value, Source={StaticResource ORDictionary}}"  Binding="{Binding Value}" SortMemberPath="Value" />
                                        </sdk:DataGrid.Columns>
                                    </sdk:DataGrid>
                                </StackPanel>
                            </toolkit:DataField>
                        </StackPanel>
                    </DataTemplate>
                </toolkit:DataForm.NewItemTemplate>
            </toolkit:DataForm>
        </cc:FlipControl.Rear>

这是自动生成的文件

using System;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Controls;
using System.Windows.Controls.Pivot;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Resources;
using System.Windows.Shapes;
using System.Windows.Threading;


namespace ItemControl {


public partial class Storage : System.Windows.Controls.Page {

    internal System.Windows.Controls.Grid LayoutRoot;

    internal System.Windows.Controls.ScrollViewer PageScrollViewer;

    internal System.Windows.Controls.StackPanel ContentStackPanel;

    internal System.Windows.Controls.TextBlock HeaderText;

    internal System.Windows.Controls.Expander expAdvancedSearch;

    internal System.Windows.Controls.StackPanel pnlSearch;

    internal System.Windows.Controls.HyperlinkButton lnkListView;

    internal System.Windows.Controls.HyperlinkButton lnkPivotView;

    internal System.Windows.Controls.ComboBox cbSearch;

    internal System.Windows.Controls.TextBox tbSearch;

    internal System.Windows.Controls.StackPanel pnlFilter;

    internal System.Windows.Controls.ComboBox cbOriginator;

    internal System.Windows.Controls.ComboBox cbStatus;

    internal System.Windows.Controls.TextBox tbItem;

    internal System.Windows.Controls.TextBox tbContract;

    internal System.Windows.Controls.TextBox tbComment;

    internal CAESL.Controls.FlipControl flipControl;

    internal System.Windows.Controls.DataGrid dgStorages;

    internal System.Windows.Controls.ContextMenu contextMenu;

    internal System.Windows.Controls.MenuItem cmdAdd;

    internal System.Windows.Controls.Separator sAdd;

    internal System.Windows.Controls.Separator sRefresh;

    internal System.Windows.Controls.MenuItem cmdRefresh;

    internal System.Windows.Controls.Separator sSave;

    internal System.Windows.Controls.MenuItem cmdSave;

    internal System.Windows.Controls.Pivot.PivotViewer pvStorages;

    internal System.Windows.Controls.DataForm dfStorages;

    private bool _contentLoaded;

    /// <summary>
    /// InitializeComponent
    /// </summary>
    [System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public void InitializeComponent() {
        if (_contentLoaded) {
            return;
        }
        _contentLoaded = true;
        System.Windows.Application.LoadComponent(this, new System.Uri("/ItemControl;component/Views/Storage.xaml", System.UriKind.Relative));
        this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
        this.PageScrollViewer = ((System.Windows.Controls.ScrollViewer)(this.FindName("PageScrollViewer")));
        this.ContentStackPanel = ((System.Windows.Controls.StackPanel)(this.FindName("ContentStackPanel")));
        this.HeaderText = ((System.Windows.Controls.TextBlock)(this.FindName("HeaderText")));
        this.expAdvancedSearch = ((System.Windows.Controls.Expander)(this.FindName("expAdvancedSearch")));
        this.pnlSearch = ((System.Windows.Controls.StackPanel)(this.FindName("pnlSearch")));
        this.lnkListView = ((System.Windows.Controls.HyperlinkButton)(this.FindName("lnkListView")));
        this.lnkPivotView = ((System.Windows.Controls.HyperlinkButton)(this.FindName("lnkPivotView")));
        this.cbSearch = ((System.Windows.Controls.ComboBox)(this.FindName("cbSearch")));
        this.tbSearch = ((System.Windows.Controls.TextBox)(this.FindName("tbSearch")));
        this.pnlFilter = ((System.Windows.Controls.StackPanel)(this.FindName("pnlFilter")));
        this.cbOriginator = ((System.Windows.Controls.ComboBox)(this.FindName("cbOriginator")));
        this.cbStatus = ((System.Windows.Controls.ComboBox)(this.FindName("cbStatus")));
        this.tbItem = ((System.Windows.Controls.TextBox)(this.FindName("tbItem")));
        this.tbContract = ((System.Windows.Controls.TextBox)(this.FindName("tbContract")));
        this.tbComment = ((System.Windows.Controls.TextBox)(this.FindName("tbComment")));
        this.flipControl = ((CAESL.Controls.FlipControl)(this.FindName("flipControl")));
        this.dgStorages = ((System.Windows.Controls.DataGrid)(this.FindName("dgStorages")));
        this.contextMenu = ((System.Windows.Controls.ContextMenu)(this.FindName("contextMenu")));
        this.cmdAdd = ((System.Windows.Controls.MenuItem)(this.FindName("cmdAdd")));
        this.sAdd = ((System.Windows.Controls.Separator)(this.FindName("sAdd")));
        this.sRefresh = ((System.Windows.Controls.Separator)(this.FindName("sRefresh")));
        this.cmdRefresh = ((System.Windows.Controls.MenuItem)(this.FindName("cmdRefresh")));
        this.sSave = ((System.Windows.Controls.Separator)(this.FindName("sSave")));
        this.cmdSave = ((System.Windows.Controls.MenuItem)(this.FindName("cmdSave")));
        this.pvStorages = ((System.Windows.Controls.Pivot.PivotViewer)(this.FindName("pvStorages")));
        this.dfStorages = ((System.Windows.Controls.DataForm)(this.FindName("dfStorages")));
    }
}

}

如您所见,cbDestination不存在,因此似乎无法进行修改(顺便说一句,我是Silverlight的新手)。我试图出于测试目的手动修改自动生成的文件,但设法进入了组合框并设置了它的itemSource。

谢谢

0 个答案:

没有答案