我不太清楚问题出在哪里,因为我几乎肯定我做了其他帖子让我做的事情。我以前已经将字符串的观察集绑定到一个comboBox,所以它应该能工作。
dataClass:
namespace UIBlocksLib.Data_VM__classes
{
public class BlockController : INotify, IStatementCollection
{
private List<UIStackBlock> _mUIStackBlocks = new List<UIStackBlock>();
public ObservableCollection<string> _mUIVariables = new ObservableCollection<string>() { "VariableA", "VariableB", "VariableC" };
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<string> getVariables
{
get
{
return _mUIVariables;
}
set
{
_mUIVariables = value;
onPropertyChanged("_mUIVariables");
}
}
public BlockController()
{
}
public void addVariable(string aVariableName)
{
_mUIVariables.Add(aVariableName);
onPropertyChanged("_mUIVariables");
}
public void addUIStackBlock(UIStackBlock aUIStackBlock)
{
throw new NotImplementedException();
}
public void onPropertyChanged(string aPropertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(aPropertyName));
}
public void removeStackBlockByIndex(int aIndex)
{
throw new NotImplementedException();
}
}
}我的objectDataProvider在我的generic.xaml里
<ObjectDataProvider x:Key="dataObject"
ObjectType="{x:Type dataClass:BlockController}"
MethodName="getVariables">
</ObjectDataProvider>和我的风格,这是我的班级的必然
<Style TargetType="{x:Type local:UISet}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:UISet}">
<Grid>
<Rectangle MouseLeftButtonDown="MouseLeftButtonDown" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Fill="#AD2B27" ClipToBounds="True"/>
<ComboBox DataContext="{staticResource dataObject}" Background="#FFEE4A4A" x:Name="comboBox" MinHeight="30" MinWidth="70" Margin="5, 23" ItemsSource="{Binding}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>还尝试使上下文静态/不使用上下文/使用变量的名称。编译器在查看建议时确实会识别getVariables。
发布于 2017-04-24 10:01:57
在您的代码中,getVariables不是一个方法,而是一个属性。这样,它就应该发挥作用:
<ObjectDataProvider x:Key="dataObject"
ObjectType="{x:Type dataClass:BlockController}"
MethodName="GetVariables">
</ObjectDataProvider>
public ObservableCollection<string> GetVariables()
{
return getVariables;
}https://stackoverflow.com/questions/43584249
复制相似问题